Skip to content

Commit

Permalink
fix: incorrect reference to quantization file
Browse files Browse the repository at this point in the history
Fixes issue #4 pilancilab/matrix-compressor.
  • Loading branch information
VarunSrivastavaIITD committed Nov 21, 2023
1 parent d3fa5c1 commit 2d53a4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
22 changes: 3 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,15 @@ You can try out the image compression experiments from the paper using `example.

## 📊 Replicating experiments in paper

### LlaMa Layer Analysis
### LlaMa Layer wise Analysis

Replace the MODEL_DIRECTORY by the location of the unquantized model, and adjust parameters `b1`, `b2` and `cr`.

```bash
export OUTPUT_DIRECTORY="./artifacts/llama-quantized"
export MODEL_DIRECTORY="./artifacts/llama-7b-hf/"
export LOGURU_LEVEL=INFO
stdbuf -oL python scripts/llama/layer_wise_quantization.py --model-directory $MODEL_DIRECTORY --output-directory $OUTPUT_DIRECTORY --b1 8 --b2 8 --cr 1 --map-location "cuda:1" 2>&1 | stdbuf -oL tee -i $OUTPUT_DIRECTORY/quantization-$(date +%m%d%H%M%S).log
stdbuf -oL python scripts/llama/per_layer_naive_quantization_comparison/lplr_vanilla.py --model-directory $MODEL_DIRECTORY --output-directory $OUTPUT_DIRECTORY --b1 8 --b2 8 --cr 1 --map-location "cuda:1" 2>&1 | stdbuf -oL tee -i $OUTPUT_DIRECTORY/quantization-$(date +%m%d%H%M%S).log
```

### Quantization and Evaluation

```bash
export RF=0.8
export B1=16
export B2=16
export CUDA_VISIBLE_DEVICES=1
export LOGURU_LEVEL=TRACE
export INPUT_DIR=artifacts/llama-7b-hf
export OUTPUT_DIR=artifacts/llama-quantized-svd-r{$RF}-{$B1}-{$B2}

stdbuf --output=L python scripts/lplr/quantize_torch_splits_svd.py --in-path $INPUT_DIR --out-path $OUTPUT_DIR --map-device 'cuda:0' --rank-fraction $RF --b1 $B1 --b2 $B2 2>&1 | stdbuf --output=L tee $OUTPUT_DIR/quantization.log

cp artifacts/llama-7b-hf/tokenizer.model artifacts/llama-7b-hf/*.json $INPUT_DIR

stdbuf --output=L python repos/lm-evaluation-harness/main.py --model hf-causal --model_args pretrained=/home/rsaha/varun/matrix-compressor/$INPUT_DIR --tasks boolq,hellaswag,piqa 2>&1 | stdbuf --output=L tee $INPUT_DIR/evaluation.log
```
Replace the file `lplr_vanilla.py` by the corresponding variant in the folder `scripts/llama/per_layer_naive_quantization_comparison` to use LSVD/DSVD.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
# Gaussian
stdbuf -oL python scripts/llama/layer_wise_lplr_quantization.py --model-directory $MODEL_DIRECTORY --output-directory $OUTPUT_DIRECTORY --b1 8 --b2 8 --b_nq 8 --cr 1 --map-location "cuda:1" 2>&1 | stdbuf -oL tee -i $OUTPUT_DIRECTORY/quantization-$(date +%m%d%H%M%S).log
stdbuf -oL python scripts/llama/per_layer_naive_quantization_comparison/lplr_vanilla.py --model-directory $MODEL_DIRECTORY --output-directory $OUTPUT_DIRECTORY --b1 8 --b2 8 --b_nq 8 --cr 1 --map-location "cuda:1" 2>&1 | stdbuf -oL tee -i $OUTPUT_DIRECTORY/quantization-$(date +%m%d%H%M%S).log
# Sparse JL
stdbuf -oL python scripts/llama/layer_wise_lplr_quantization.py --model-directory $MODEL_DIRECTORY --output-directory $OUTPUT_DIRECTORY --b1 8 --b2 8 --b_nq 8 --cr 1 --map-location "cuda:2" 2>&1 --sketch SparseJL --sparse-jl-s 1 | stdbuf -oL tee -i $OUTPUT_DIRECTORY/quantization-$(date +%m%d%H%M%S).log
stdbuf -oL python scripts/llama/per_layer_naive_quantization_comparison/lplr_vanilla.py --model-directory $MODEL_DIRECTORY --output-directory $OUTPUT_DIRECTORY --b1 8 --b2 8 --b_nq 8 --cr 1 --map-location "cuda:2" 2>&1 --sketch SparseJL --sparse-jl-s 1 | stdbuf -oL tee -i $OUTPUT_DIRECTORY/quantization-$(date +%m%d%H%M%S).log
"""
import json
import pathlib
Expand Down Expand Up @@ -74,15 +74,16 @@ def main(

col_output_rank = maximum_output_rank(cr, b1, b2, b_nq, col_input.shape)
row_output_rank = maximum_output_rank(cr, b1, b2, b_nq, row_input.shape)
logger.debug(f"Name: {name} "
logger.debug(
f"Name: {name} "
f"Shape: {weights.shape} "
f"Row Output Rank: {row_output_rank} "
f"Col Output Rank: {col_output_rank}"
)
)

if b1 == b2:
assert col_output_rank == row_output_rank

col_sketch = lplr(
col_input, col_output_rank, b1, b2, sketch=sketch, **kwargs
)
Expand Down

0 comments on commit 2d53a4f

Please sign in to comment.