Skip to content

Commit 83cf9b7

Browse files
Yuan0320jpablomch
andcommitted
Improve READMEs (#3)
Align with open-source repo Add SQFT bibtex and Remove abstract Updated device_map configuration to auto refactor: move datasets to global scope Update environment in notebooks feat: Add support for automatic generation of NNCF Config files refactor: Replace ${...} with <...> to improve readability Add device_map in check_sparsity.py Refactor type annotations for compatibility (Python versions below 3.9) Add missing 'fi' to if-else statements in script --------- Signed-off-by: Yuan0320 <[email protected]> Co-authored-by: J. Pablo Muñoz <[email protected]>
1 parent 24cd587 commit 83cf9b7

35 files changed

+5902
-5551
lines changed

LoNAS/README.md

+19-7
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,25 @@ Please refer to `running_commands` for all commands related to reproducing the p
170170
# Citation
171171

172172
```bibtex
173-
@inproceedings{
174-
munoz2024lonas,
175-
title={LoNAS: Elastic Low-Rank Adapters for Efficient Large Language Models},
176-
author={J. Pablo Muñoz and Jinjie Yuan and Yi Zheng and Nilesh Jain},
177-
booktitle={The 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation},
178-
year={2024},
179-
url={https://aclanthology.org/2024.lrec-main.940/}
173+
@inproceedings{munoz-etal-2024-lonas,
174+
title = "{L}o{NAS}: Elastic Low-Rank Adapters for Efficient Large Language Models",
175+
author = "Munoz, Juan Pablo and
176+
Yuan, Jinjie and
177+
Zheng, Yi and
178+
Jain, Nilesh",
179+
editor = "Calzolari, Nicoletta and
180+
Kan, Min-Yen and
181+
Hoste, Veronique and
182+
Lenci, Alessandro and
183+
Sakti, Sakriani and
184+
Xue, Nianwen",
185+
booktitle = "Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024)",
186+
month = may,
187+
year = "2024",
188+
address = "Torino, Italia",
189+
publisher = "ELRA and ICCL",
190+
url = "https://aclanthology.org/2024.lrec-main.940",
191+
pages = "10760--10776",
180192
}
181193
```
182194

LoNAS/run_commonsense.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def main():
224224
model_args.model_name_or_path,
225225
load_in_8bit=False,
226226
torch_dtype=torch.float16,
227-
device_map={"": 0},
227+
device_map="auto",
228228
trust_remote_code=True,
229229
cache_dir=model_args.cache_dir,
230230
)
@@ -243,7 +243,7 @@ def main():
243243
model.print_trainable_parameters()
244244
elif training_args.lora:
245245
logger.info("Loading LoRA modules...")
246-
model = PeftModel.from_pretrained(model, model_args.lora_weights, torch_dtype=torch.float16, device_map={"": 0})
246+
model = PeftModel.from_pretrained(model, model_args.lora_weights, torch_dtype=torch.float16, device_map="auto")
247247

248248
nncf_config = None
249249
if training_args.nncf_config is not None:

LoNAS/run_glue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def get_inputs(self, dataloader_output):
558558
model.print_trainable_parameters()
559559
elif training_args.lora:
560560
logger.info("Loading LoRA modules...")
561-
model = PeftModel.from_pretrained(model, model_args.lora_weights, device_map={"": 0})
561+
model = PeftModel.from_pretrained(model, model_args.lora_weights, device_map="auto")
562562

563563
compression_ctrl = None
564564
if nncf_config is not None:

LoNAS/run_math.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def main():
244244
model_args.model_name_or_path,
245245
load_in_8bit=False,
246246
torch_dtype=torch.float16,
247-
device_map={"": 0},
247+
device_map="auto",
248248
trust_remote_code=True,
249249
cache_dir=model_args.cache_dir,
250250
)
@@ -263,7 +263,7 @@ def main():
263263
model.print_trainable_parameters()
264264
elif training_args.lora:
265265
logger.info("Loading LoRA modules...")
266-
model = PeftModel.from_pretrained(model, model_args.lora_weights, torch_dtype=torch.float16, device_map={"": 0})
266+
model = PeftModel.from_pretrained(model, model_args.lora_weights, torch_dtype=torch.float16, device_map="auto")
267267

268268
nncf_config = None
269269
if training_args.nncf_config is not None:

SQFT/README.md

+78-97
Large diffs are not rendered by default.

SQFT/eval/evaluate_math.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from peft import PeftModel
1212

1313

14+
DATASETS = ["mawps", "SVAMP", "gsm8k"]
15+
1416
def extract_answer_number(dataset_name: str, sentence: str) -> float:
1517
"""
1618
Extracts the numerical answer from a given sentence based on the dataset type.
@@ -194,9 +196,7 @@ def main():
194196
dtype = args.dtype
195197
adapter_model_path = args.adapter_model_path
196198
output_dir = args.output_dir
197-
198199
os.makedirs(output_dir, exist_ok=True)
199-
datasets = ["mawps", "SVAMP", "gsm8k"]
200200

201201
tokenizer = AutoTokenizer.from_pretrained(
202202
base_model_path if tokenizer_path is None else tokenizer_path,
@@ -205,13 +205,13 @@ def main():
205205

206206
model = AutoModelForCausalLM.from_pretrained(
207207
base_model_path,
208-
device_map={"": 0},
208+
device_map="auto",
209209
trust_remote_code=True,
210210
torch_dtype=dtype,
211211
)
212212

213213
if adapter_model_path is not None:
214-
model = PeftModel.from_pretrained(model, adapter_model_path, torch_dtype=dtype, device_map={"": 0})
214+
model = PeftModel.from_pretrained(model, adapter_model_path, torch_dtype=dtype, device_map="auto")
215215

216216
model.eval()
217217

@@ -222,7 +222,7 @@ def main():
222222
else:
223223
dataset_to_accuracy = {}
224224

225-
for dataset_name in datasets:
225+
for dataset_name in DATASETS:
226226
if dataset_name in dataset_to_accuracy:
227227
continue
228228
print(f"*** Evaluation on {dataset_name} ***")
@@ -231,7 +231,7 @@ def main():
231231
dataset_to_accuracy[dataset_name] = accuracy
232232
print(f"{dataset_name} - Accuracy: {accuracy}")
233233

234-
accuracies = [acc for dataset_name, acc in dataset_to_accuracy.items() if dataset_name in datasets]
234+
accuracies = [acc for dataset_name, acc in dataset_to_accuracy.items() if dataset_name in DATASETS]
235235
average_accuracy = sum(accuracies) / len(accuracies)
236236
dataset_to_accuracy["average"] = average_accuracy
237237
with open(result_file_path, "w") as file:

SQFT/install.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ mkdir third_party && cd third_party
99

1010
# transformers
1111
git clone https://github.com/huggingface/transformers.git
12-
cd transformers && git checkout v4.44.2 && git apply --ignore-space-change --ignore-whitespace ${SQFT_PATH}/patches/transformers-modifications-for-sqft-usage.patch && pip install -e . && cd ..
12+
cd transformers && git checkout v4.44.2 && git apply --ignore-space-change --ignore-whitespace ${SQFT_PATH}/patches/transformers-v4.44.2.patch && pip install -e . && cd ..
1313

1414
# peft
1515
git clone https://github.com/huggingface/peft.git
16-
cd peft && git checkout v0.10.0 && git apply --ignore-space-change --ignore-whitespace ${SQFT_PATH}/patches/peft-modifications-for-sqft-usage.patch && pip install -e . && cd ..
16+
cd peft && git checkout v0.10.0 && git apply --ignore-space-change --ignore-whitespace ${SQFT_PATH}/patches/peft-v0.10.0.patch && pip install -e . && cd ..
1717

1818
pip install datasets accelerate sentencepiece protobuf
1919
pip install optimum==1.18.0 --no-deps
2020
pip install git+https://github.com/AutoGPTQ/AutoGPTQ@866b4c8
2121

2222
# nncf
2323
git clone https://github.com/openvinotoolkit/nncf.git
24-
cd nncf && git checkout v2.12.0 && git apply --ignore-space-change --ignore-whitespace ${SQFT_PATH}/patches/nncf-modifications-for-sqft-usage.patch && pip install -e . && cd ..
24+
cd nncf && git checkout v2.12.0 && git apply --ignore-space-change --ignore-whitespace ${SQFT_PATH}/patches/nncf-v2.12.0.patch && pip install -e . && cd ..
2525

2626
# lm-eval-harness
2727
pip install lm-eval==0.4.2

SQFT/install_inference.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -x
55
pip install 'numpy<2.0.0' setuptools==69.5.1 wheel
66

77
# transformers
8-
pip install transformers==v4.44.2
8+
pip install transformers==4.44.2
99
pip install datasets accelerate sentencepiece protobuf
1010
pip install optimum==1.18.0 --no-deps
1111
pip install git+https://github.com/AutoGPTQ/AutoGPTQ@866b4c8
@@ -14,7 +14,7 @@ pip install git+https://github.com/AutoGPTQ/AutoGPTQ@866b4c8
1414
SQFT_PATH=$PWD
1515
mkdir third_party_inference && cd third_party_inference
1616
git clone https://github.com/huggingface/peft.git
17-
cd peft && git checkout v0.10.0 && git apply --ignore-space-change --ignore-whitespace ${SQFT_PATH}/patches/peft-modifications-for-sqft-usage.patch && pip install -e . && cd ..
17+
cd peft && git checkout v0.10.0 && git apply --ignore-space-change --ignore-whitespace ${SQFT_PATH}/patches/peft-v0.10.0.patch && pip install -e . && cd ..
1818

1919
# lm-eval-harness (for evaluation)
2020
pip install lm-eval==0.4.2

SQFT/modules/sqft_linear.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional
1+
from typing import List, Optional
22

33
import numpy as np
44
import torch
@@ -197,11 +197,11 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
197197

198198
return result
199199

200-
def merge(self, safe_merge: bool = False, adapter_names: Optional[list[str]] = None) -> None:
200+
def merge(self, safe_merge: bool = False, adapter_names: Optional[List[str]] = None) -> None:
201201
"""
202202
Merges the adapter weights into the base weight.
203203
204-
Referenced from:
204+
Reference:
205205
https://github.com/AutoGPTQ/AutoGPTQ/blob/866b4c8c2cbb893f1156cb6c114625bba2e4d7c5/auto_gptq/nn_modules/qlinear/qlinear_cuda_old.py#L135-L140
206206
"""
207207
base_weight = self.base_weight

0 commit comments

Comments
 (0)