fix: synced_gpus must be passed to generate(), not GenerationConfig
Browse filestransformers 4.40+ raises ValueError if synced_gpus is included in
GenerationConfig(**gen_kwargs). Pop it out before constructing the
config and pass it directly to every model.generate() call instead.
Affects all cl_trainer_*.py files in both root and improve codebases:
- cl_trainer_gainlora_inflora.py
- cl_trainer_inflora.py
- cl_trainer_olora.py
- cl_trainer_gainlora_olora_llama.py
- cl_trainer_gainlora_inflora_llama.py
- cl_trainer_inflora_llama.py
- cl_trainer_gainlora_olora.py
Does not affect T5-large scripts (same fix, backward compatible).
- fix_synced_gpus.py +50 -0
- fix_synced_gpus2.py +60 -0
- improve_gainlora/src/cl_trainer_gainlora_inflora.py +4 -0
- improve_gainlora/src/cl_trainer_gainlora_inflora_llama.py +4 -0
- improve_gainlora/src/cl_trainer_gainlora_olora.py +4 -0
- improve_gainlora/src/cl_trainer_gainlora_olora_llama.py +4 -0
- improve_gainlora/src/cl_trainer_inflora.py +4 -0
- improve_gainlora/src/cl_trainer_inflora_llama.py +4 -0
- root_gainlora/src/cl_trainer_gainlora_inflora.py +4 -1
- root_gainlora/src/cl_trainer_gainlora_inflora_llama.py +4 -0
- root_gainlora/src/cl_trainer_gainlora_olora_llama.py +4 -0
- root_gainlora/src/cl_trainer_inflora.py +4 -0
- root_gainlora/src/cl_trainer_olora.py +4 -0
fix_synced_gpus.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re, pathlib
|
| 2 |
+
|
| 3 |
+
FILES = [
|
| 4 |
+
"root_gainlora/src/cl_trainer_inflora.py",
|
| 5 |
+
"root_gainlora/src/cl_trainer_olora.py",
|
| 6 |
+
"root_gainlora/src/cl_trainer_gainlora_olora_llama.py",
|
| 7 |
+
"root_gainlora/src/cl_trainer_gainlora_inflora_llama.py",
|
| 8 |
+
"improve_gainlora/src/cl_trainer_gainlora_inflora.py",
|
| 9 |
+
"improve_gainlora/src/cl_trainer_inflora.py",
|
| 10 |
+
"improve_gainlora/src/cl_trainer_inflora_llama.py",
|
| 11 |
+
"improve_gainlora/src/cl_trainer_gainlora_olora.py",
|
| 12 |
+
"improve_gainlora/src/cl_trainer_gainlora_olora_llama.py",
|
| 13 |
+
"improve_gainlora/src/cl_trainer_gainlora_inflora_llama.py",
|
| 14 |
+
]
|
| 15 |
+
|
| 16 |
+
for rel in FILES:
|
| 17 |
+
p = pathlib.Path(rel)
|
| 18 |
+
txt = p.read_text()
|
| 19 |
+
|
| 20 |
+
# Skip if already fixed
|
| 21 |
+
if 'gen_kwargs.pop("synced_gpus"' in txt:
|
| 22 |
+
pop_idx = txt.index('gen_kwargs.pop("synced_gpus"')
|
| 23 |
+
gc_idx = txt.index('generation_config = GenerationConfig(**gen_kwargs)')
|
| 24 |
+
if pop_idx < gc_idx:
|
| 25 |
+
print(f" ALREADY FIXED: {rel}")
|
| 26 |
+
continue
|
| 27 |
+
|
| 28 |
+
old_gc = ' generation_config = GenerationConfig(**gen_kwargs)'
|
| 29 |
+
new_gc = ' synced_gpus = gen_kwargs.pop("synced_gpus", False)\n generation_config = GenerationConfig(**gen_kwargs)'
|
| 30 |
+
if old_gc not in txt:
|
| 31 |
+
print(f" WARNING: GenerationConfig pattern not found in {rel}")
|
| 32 |
+
continue
|
| 33 |
+
txt = txt.replace(old_gc, new_gc, 1)
|
| 34 |
+
|
| 35 |
+
# Add synced_gpus= to each generate() call after generation_config= line
|
| 36 |
+
txt = re.sub(
|
| 37 |
+
r'(generation_config=generation_config,)\n(\s+\))',
|
| 38 |
+
r'\1\n\2 synced_gpus=synced_gpus,\n\2',
|
| 39 |
+
txt,
|
| 40 |
+
)
|
| 41 |
+
txt = re.sub(
|
| 42 |
+
r'(generation_config=generation_config)\n(\s+\))',
|
| 43 |
+
r'\1,\n\2 synced_gpus=synced_gpus,\n\2',
|
| 44 |
+
txt,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
p.write_text(txt)
|
| 48 |
+
print(f" FIXED: {rel}")
|
| 49 |
+
|
| 50 |
+
print("Done")
|
fix_synced_gpus2.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fix the broken synced_gpus insertion: convert
|
| 2 |
+
generation_config=generation_config,
|
| 3 |
+
) synced_gpus=synced_gpus,
|
| 4 |
+
)
|
| 5 |
+
to the correct form:
|
| 6 |
+
generation_config=generation_config,
|
| 7 |
+
synced_gpus=synced_gpus,
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
This must be idempotent.
|
| 11 |
+
"""
|
| 12 |
+
import re, pathlib
|
| 13 |
+
|
| 14 |
+
FILES = [
|
| 15 |
+
"root_gainlora/src/cl_trainer_inflora.py",
|
| 16 |
+
"root_gainlora/src/cl_trainer_olora.py",
|
| 17 |
+
"root_gainlora/src/cl_trainer_gainlora_olora_llama.py",
|
| 18 |
+
"root_gainlora/src/cl_trainer_gainlora_inflora_llama.py",
|
| 19 |
+
"root_gainlora/src/cl_trainer_gainlora_inflora.py", # already done manually but check
|
| 20 |
+
"improve_gainlora/src/cl_trainer_gainlora_inflora.py",
|
| 21 |
+
"improve_gainlora/src/cl_trainer_inflora.py",
|
| 22 |
+
"improve_gainlora/src/cl_trainer_inflora_llama.py",
|
| 23 |
+
"improve_gainlora/src/cl_trainer_gainlora_olora.py",
|
| 24 |
+
"improve_gainlora/src/cl_trainer_gainlora_olora_llama.py",
|
| 25 |
+
"improve_gainlora/src/cl_trainer_gainlora_inflora_llama.py",
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
# Pattern produced by the broken regex:
|
| 29 |
+
# generation_config=generation_config,\n{ws}) synced_gpus=synced_gpus,\n{ws})
|
| 30 |
+
BAD_PAT = re.compile(
|
| 31 |
+
r'(generation_config=generation_config,)\n'
|
| 32 |
+
r'( +)\) synced_gpus=synced_gpus,\n'
|
| 33 |
+
r'( +\))'
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
# Correct form: synced_gpus goes INSIDE the call, before the closing paren
|
| 37 |
+
# We add 4 extra spaces relative to the closing-paren indent level.
|
| 38 |
+
def fix_bad(txt):
|
| 39 |
+
def replacer(m):
|
| 40 |
+
arg_line = m.group(1) # generation_config=generation_config,
|
| 41 |
+
inner_ws = m.group(2) # whitespace before the doubled )
|
| 42 |
+
close_paren = m.group(3) # whitespace + )
|
| 43 |
+
# synced_gpus should be indented 4 more than the closing paren indent
|
| 44 |
+
synced_ws = inner_ws + " "
|
| 45 |
+
return f"{arg_line}\n{synced_ws}synced_gpus=synced_gpus,\n{close_paren}"
|
| 46 |
+
return BAD_PAT.sub(replacer, txt)
|
| 47 |
+
|
| 48 |
+
for rel in FILES:
|
| 49 |
+
p = pathlib.Path(rel)
|
| 50 |
+
txt = p.read_text()
|
| 51 |
+
|
| 52 |
+
if ") synced_gpus=synced_gpus," in txt:
|
| 53 |
+
fixed = fix_bad(txt)
|
| 54 |
+
p.write_text(fixed)
|
| 55 |
+
n = txt.count(") synced_gpus=synced_gpus,")
|
| 56 |
+
print(f" FIXED ({n} occurrences): {rel}")
|
| 57 |
+
else:
|
| 58 |
+
print(f" OK (no bad pattern): {rel}")
|
| 59 |
+
|
| 60 |
+
print("Done")
|
improve_gainlora/src/cl_trainer_gainlora_inflora.py
CHANGED
|
@@ -909,6 +909,7 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 909 |
if "attention_mask" in inputs:
|
| 910 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 911 |
|
|
|
|
| 912 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 913 |
|
| 914 |
# prepare generation inputs
|
|
@@ -920,6 +921,7 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 920 |
generated_tokens = self.model.generate(
|
| 921 |
input_ids=generation_inputs,
|
| 922 |
generation_config=generation_config,
|
|
|
|
| 923 |
)
|
| 924 |
else:
|
| 925 |
generation_inputs = inputs[self.model.main_input_name]
|
|
@@ -929,12 +931,14 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 929 |
input_ids=generation_inputs,
|
| 930 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 931 |
generation_config=generation_config,
|
|
|
|
| 932 |
)
|
| 933 |
|
| 934 |
else:
|
| 935 |
generated_tokens = self.model.generate(
|
| 936 |
input_ids=generation_inputs,
|
| 937 |
generation_config=generation_config,
|
|
|
|
| 938 |
)
|
| 939 |
|
| 940 |
bs, source_len = inputs['input_ids'].shape
|
|
|
|
| 909 |
if "attention_mask" in inputs:
|
| 910 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 911 |
|
| 912 |
+
synced_gpus = gen_kwargs.pop("synced_gpus", False)
|
| 913 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 914 |
|
| 915 |
# prepare generation inputs
|
|
|
|
| 921 |
generated_tokens = self.model.generate(
|
| 922 |
input_ids=generation_inputs,
|
| 923 |
generation_config=generation_config,
|
| 924 |
+
synced_gpus=synced_gpus,
|
| 925 |
)
|
| 926 |
else:
|
| 927 |
generation_inputs = inputs[self.model.main_input_name]
|
|
|
|
| 931 |
input_ids=generation_inputs,
|
| 932 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 933 |
generation_config=generation_config,
|
| 934 |
+
synced_gpus=synced_gpus,
|
| 935 |
)
|
| 936 |
|
| 937 |
else:
|
| 938 |
generated_tokens = self.model.generate(
|
| 939 |
input_ids=generation_inputs,
|
| 940 |
generation_config=generation_config,
|
| 941 |
+
synced_gpus=synced_gpus,
|
| 942 |
)
|
| 943 |
|
| 944 |
bs, source_len = inputs['input_ids'].shape
|
improve_gainlora/src/cl_trainer_gainlora_inflora_llama.py
CHANGED
|
@@ -940,6 +940,7 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 940 |
if "attention_mask" in inputs:
|
| 941 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 942 |
|
|
|
|
| 943 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 944 |
|
| 945 |
# prepare generation inputs
|
|
@@ -951,6 +952,7 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 951 |
generated_tokens = self.model.generate(
|
| 952 |
input_ids=generation_inputs,
|
| 953 |
generation_config=generation_config,
|
|
|
|
| 954 |
)
|
| 955 |
else:
|
| 956 |
generation_inputs = inputs[self.model.main_input_name]
|
|
@@ -960,12 +962,14 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 960 |
input_ids=generation_inputs,
|
| 961 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 962 |
generation_config=generation_config,
|
|
|
|
| 963 |
)
|
| 964 |
|
| 965 |
else:
|
| 966 |
generated_tokens = self.model.generate(
|
| 967 |
input_ids=generation_inputs,
|
| 968 |
generation_config=generation_config,
|
|
|
|
| 969 |
)
|
| 970 |
|
| 971 |
bs, source_len = inputs['input_ids'].shape
|
|
|
|
| 940 |
if "attention_mask" in inputs:
|
| 941 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 942 |
|
| 943 |
+
synced_gpus = gen_kwargs.pop("synced_gpus", False)
|
| 944 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 945 |
|
| 946 |
# prepare generation inputs
|
|
|
|
| 952 |
generated_tokens = self.model.generate(
|
| 953 |
input_ids=generation_inputs,
|
| 954 |
generation_config=generation_config,
|
| 955 |
+
synced_gpus=synced_gpus,
|
| 956 |
)
|
| 957 |
else:
|
| 958 |
generation_inputs = inputs[self.model.main_input_name]
|
|
|
|
| 962 |
input_ids=generation_inputs,
|
| 963 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 964 |
generation_config=generation_config,
|
| 965 |
+
synced_gpus=synced_gpus,
|
| 966 |
)
|
| 967 |
|
| 968 |
else:
|
| 969 |
generated_tokens = self.model.generate(
|
| 970 |
input_ids=generation_inputs,
|
| 971 |
generation_config=generation_config,
|
| 972 |
+
synced_gpus=synced_gpus,
|
| 973 |
)
|
| 974 |
|
| 975 |
bs, source_len = inputs['input_ids'].shape
|
improve_gainlora/src/cl_trainer_gainlora_olora.py
CHANGED
|
@@ -948,6 +948,7 @@ class GainLoRA_OLoRA_Trainer(Seq2SeqTrainer):
|
|
| 948 |
if "attention_mask" in inputs:
|
| 949 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 950 |
|
|
|
|
| 951 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 952 |
|
| 953 |
# prepare generation inputs
|
|
@@ -959,6 +960,7 @@ class GainLoRA_OLoRA_Trainer(Seq2SeqTrainer):
|
|
| 959 |
generated_tokens = self.model.generate(
|
| 960 |
input_ids=generation_inputs,
|
| 961 |
generation_config=generation_config,
|
|
|
|
| 962 |
)
|
| 963 |
else:
|
| 964 |
generation_inputs = inputs[self.model.main_input_name]
|
|
@@ -968,12 +970,14 @@ class GainLoRA_OLoRA_Trainer(Seq2SeqTrainer):
|
|
| 968 |
input_ids=generation_inputs,
|
| 969 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 970 |
generation_config=generation_config,
|
|
|
|
| 971 |
)
|
| 972 |
|
| 973 |
else:
|
| 974 |
generated_tokens = self.model.generate(
|
| 975 |
input_ids=generation_inputs,
|
| 976 |
generation_config=generation_config,
|
|
|
|
| 977 |
)
|
| 978 |
|
| 979 |
bs, source_len = inputs['input_ids'].shape
|
|
|
|
| 948 |
if "attention_mask" in inputs:
|
| 949 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 950 |
|
| 951 |
+
synced_gpus = gen_kwargs.pop("synced_gpus", False)
|
| 952 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 953 |
|
| 954 |
# prepare generation inputs
|
|
|
|
| 960 |
generated_tokens = self.model.generate(
|
| 961 |
input_ids=generation_inputs,
|
| 962 |
generation_config=generation_config,
|
| 963 |
+
synced_gpus=synced_gpus,
|
| 964 |
)
|
| 965 |
else:
|
| 966 |
generation_inputs = inputs[self.model.main_input_name]
|
|
|
|
| 970 |
input_ids=generation_inputs,
|
| 971 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 972 |
generation_config=generation_config,
|
| 973 |
+
synced_gpus=synced_gpus,
|
| 974 |
)
|
| 975 |
|
| 976 |
else:
|
| 977 |
generated_tokens = self.model.generate(
|
| 978 |
input_ids=generation_inputs,
|
| 979 |
generation_config=generation_config,
|
| 980 |
+
synced_gpus=synced_gpus,
|
| 981 |
)
|
| 982 |
|
| 983 |
bs, source_len = inputs['input_ids'].shape
|
improve_gainlora/src/cl_trainer_gainlora_olora_llama.py
CHANGED
|
@@ -931,6 +931,7 @@ class GainLoRA_OLoRA_Trainer(Seq2SeqTrainer):
|
|
| 931 |
if "attention_mask" in inputs:
|
| 932 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 933 |
|
|
|
|
| 934 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 935 |
|
| 936 |
# prepare generation inputs
|
|
@@ -942,6 +943,7 @@ class GainLoRA_OLoRA_Trainer(Seq2SeqTrainer):
|
|
| 942 |
generated_tokens = self.model.generate(
|
| 943 |
input_ids=generation_inputs,
|
| 944 |
generation_config=generation_config,
|
|
|
|
| 945 |
)
|
| 946 |
else:
|
| 947 |
generation_inputs = inputs[self.model.main_input_name]
|
|
@@ -951,12 +953,14 @@ class GainLoRA_OLoRA_Trainer(Seq2SeqTrainer):
|
|
| 951 |
input_ids=generation_inputs,
|
| 952 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 953 |
generation_config=generation_config,
|
|
|
|
| 954 |
)
|
| 955 |
|
| 956 |
else:
|
| 957 |
generated_tokens = self.model.generate(
|
| 958 |
input_ids=generation_inputs,
|
| 959 |
generation_config=generation_config,
|
|
|
|
| 960 |
)
|
| 961 |
|
| 962 |
bs, source_len = inputs['input_ids'].shape
|
|
|
|
| 931 |
if "attention_mask" in inputs:
|
| 932 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 933 |
|
| 934 |
+
synced_gpus = gen_kwargs.pop("synced_gpus", False)
|
| 935 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 936 |
|
| 937 |
# prepare generation inputs
|
|
|
|
| 943 |
generated_tokens = self.model.generate(
|
| 944 |
input_ids=generation_inputs,
|
| 945 |
generation_config=generation_config,
|
| 946 |
+
synced_gpus=synced_gpus,
|
| 947 |
)
|
| 948 |
else:
|
| 949 |
generation_inputs = inputs[self.model.main_input_name]
|
|
|
|
| 953 |
input_ids=generation_inputs,
|
| 954 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 955 |
generation_config=generation_config,
|
| 956 |
+
synced_gpus=synced_gpus,
|
| 957 |
)
|
| 958 |
|
| 959 |
else:
|
| 960 |
generated_tokens = self.model.generate(
|
| 961 |
input_ids=generation_inputs,
|
| 962 |
generation_config=generation_config,
|
| 963 |
+
synced_gpus=synced_gpus,
|
| 964 |
)
|
| 965 |
|
| 966 |
bs, source_len = inputs['input_ids'].shape
|
improve_gainlora/src/cl_trainer_inflora.py
CHANGED
|
@@ -704,6 +704,7 @@ class InfLoRATrainer(Seq2SeqTrainer):
|
|
| 704 |
if "attention_mask" in inputs:
|
| 705 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 706 |
|
|
|
|
| 707 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 708 |
|
| 709 |
# prepare generation inputs
|
|
@@ -715,6 +716,7 @@ class InfLoRATrainer(Seq2SeqTrainer):
|
|
| 715 |
generated_tokens = self.model.generate(
|
| 716 |
input_ids=generation_inputs,
|
| 717 |
generation_config=generation_config,
|
|
|
|
| 718 |
)
|
| 719 |
else:
|
| 720 |
generation_inputs = inputs[self.model.main_input_name]
|
|
@@ -724,12 +726,14 @@ class InfLoRATrainer(Seq2SeqTrainer):
|
|
| 724 |
input_ids=generation_inputs,
|
| 725 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 726 |
generation_config=generation_config,
|
|
|
|
| 727 |
)
|
| 728 |
|
| 729 |
else:
|
| 730 |
generated_tokens = self.model.generate(
|
| 731 |
input_ids=generation_inputs,
|
| 732 |
generation_config=generation_config,
|
|
|
|
| 733 |
)
|
| 734 |
|
| 735 |
bs, source_len = inputs['input_ids'].shape
|
|
|
|
| 704 |
if "attention_mask" in inputs:
|
| 705 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 706 |
|
| 707 |
+
synced_gpus = gen_kwargs.pop("synced_gpus", False)
|
| 708 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 709 |
|
| 710 |
# prepare generation inputs
|
|
|
|
| 716 |
generated_tokens = self.model.generate(
|
| 717 |
input_ids=generation_inputs,
|
| 718 |
generation_config=generation_config,
|
| 719 |
+
synced_gpus=synced_gpus,
|
| 720 |
)
|
| 721 |
else:
|
| 722 |
generation_inputs = inputs[self.model.main_input_name]
|
|
|
|
| 726 |
input_ids=generation_inputs,
|
| 727 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 728 |
generation_config=generation_config,
|
| 729 |
+
synced_gpus=synced_gpus,
|
| 730 |
)
|
| 731 |
|
| 732 |
else:
|
| 733 |
generated_tokens = self.model.generate(
|
| 734 |
input_ids=generation_inputs,
|
| 735 |
generation_config=generation_config,
|
| 736 |
+
synced_gpus=synced_gpus,
|
| 737 |
)
|
| 738 |
|
| 739 |
bs, source_len = inputs['input_ids'].shape
|
improve_gainlora/src/cl_trainer_inflora_llama.py
CHANGED
|
@@ -731,6 +731,7 @@ class InfLoRATrainer(Seq2SeqTrainer):
|
|
| 731 |
if "attention_mask" in inputs:
|
| 732 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 733 |
|
|
|
|
| 734 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 735 |
|
| 736 |
# prepare generation inputs
|
|
@@ -742,6 +743,7 @@ class InfLoRATrainer(Seq2SeqTrainer):
|
|
| 742 |
generated_tokens = self.model.generate(
|
| 743 |
input_ids=generation_inputs,
|
| 744 |
generation_config=generation_config,
|
|
|
|
| 745 |
)
|
| 746 |
else:
|
| 747 |
generation_inputs = inputs[self.model.main_input_name]
|
|
@@ -751,12 +753,14 @@ class InfLoRATrainer(Seq2SeqTrainer):
|
|
| 751 |
input_ids=generation_inputs,
|
| 752 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 753 |
generation_config=generation_config,
|
|
|
|
| 754 |
)
|
| 755 |
|
| 756 |
else:
|
| 757 |
generated_tokens = self.model.generate(
|
| 758 |
input_ids=generation_inputs,
|
| 759 |
generation_config=generation_config,
|
|
|
|
| 760 |
)
|
| 761 |
|
| 762 |
bs, source_len = inputs['input_ids'].shape
|
|
|
|
| 731 |
if "attention_mask" in inputs:
|
| 732 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 733 |
|
| 734 |
+
synced_gpus = gen_kwargs.pop("synced_gpus", False)
|
| 735 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 736 |
|
| 737 |
# prepare generation inputs
|
|
|
|
| 743 |
generated_tokens = self.model.generate(
|
| 744 |
input_ids=generation_inputs,
|
| 745 |
generation_config=generation_config,
|
| 746 |
+
synced_gpus=synced_gpus,
|
| 747 |
)
|
| 748 |
else:
|
| 749 |
generation_inputs = inputs[self.model.main_input_name]
|
|
|
|
| 753 |
input_ids=generation_inputs,
|
| 754 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 755 |
generation_config=generation_config,
|
| 756 |
+
synced_gpus=synced_gpus,
|
| 757 |
)
|
| 758 |
|
| 759 |
else:
|
| 760 |
generated_tokens = self.model.generate(
|
| 761 |
input_ids=generation_inputs,
|
| 762 |
generation_config=generation_config,
|
| 763 |
+
synced_gpus=synced_gpus,
|
| 764 |
)
|
| 765 |
|
| 766 |
bs, source_len = inputs['input_ids'].shape
|
root_gainlora/src/cl_trainer_gainlora_inflora.py
CHANGED
|
@@ -933,7 +933,7 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 933 |
"pad_token_id": 0,
|
| 934 |
}
|
| 935 |
|
| 936 |
-
gen_kwargs
|
| 937 |
|
| 938 |
if "attention_mask" in inputs:
|
| 939 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
|
@@ -949,6 +949,7 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 949 |
generated_tokens = self.model.generate(
|
| 950 |
input_ids=generation_inputs,
|
| 951 |
generation_config=generation_config,
|
|
|
|
| 952 |
)
|
| 953 |
else:
|
| 954 |
generation_inputs = inputs[self.model.main_input_name]
|
|
@@ -958,12 +959,14 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 958 |
input_ids=generation_inputs,
|
| 959 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 960 |
generation_config=generation_config,
|
|
|
|
| 961 |
)
|
| 962 |
|
| 963 |
else:
|
| 964 |
generated_tokens = self.model.generate(
|
| 965 |
input_ids=generation_inputs,
|
| 966 |
generation_config=generation_config,
|
|
|
|
| 967 |
)
|
| 968 |
|
| 969 |
bs, source_len = inputs['input_ids'].shape
|
|
|
|
| 933 |
"pad_token_id": 0,
|
| 934 |
}
|
| 935 |
|
| 936 |
+
synced_gpus = gen_kwargs.pop("synced_gpus", False)
|
| 937 |
|
| 938 |
if "attention_mask" in inputs:
|
| 939 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
|
|
|
| 949 |
generated_tokens = self.model.generate(
|
| 950 |
input_ids=generation_inputs,
|
| 951 |
generation_config=generation_config,
|
| 952 |
+
synced_gpus=synced_gpus,
|
| 953 |
)
|
| 954 |
else:
|
| 955 |
generation_inputs = inputs[self.model.main_input_name]
|
|
|
|
| 959 |
input_ids=generation_inputs,
|
| 960 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 961 |
generation_config=generation_config,
|
| 962 |
+
synced_gpus=synced_gpus,
|
| 963 |
)
|
| 964 |
|
| 965 |
else:
|
| 966 |
generated_tokens = self.model.generate(
|
| 967 |
input_ids=generation_inputs,
|
| 968 |
generation_config=generation_config,
|
| 969 |
+
synced_gpus=synced_gpus,
|
| 970 |
)
|
| 971 |
|
| 972 |
bs, source_len = inputs['input_ids'].shape
|
root_gainlora/src/cl_trainer_gainlora_inflora_llama.py
CHANGED
|
@@ -941,6 +941,7 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 941 |
if "attention_mask" in inputs:
|
| 942 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 943 |
|
|
|
|
| 944 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 945 |
|
| 946 |
# prepare generation inputs
|
|
@@ -952,6 +953,7 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 952 |
generated_tokens = self.model.generate(
|
| 953 |
input_ids=generation_inputs,
|
| 954 |
generation_config=generation_config,
|
|
|
|
| 955 |
)
|
| 956 |
else:
|
| 957 |
generation_inputs = inputs[self.model.main_input_name]
|
|
@@ -961,12 +963,14 @@ class GainLoRA_InfLoRA_Trainer(Seq2SeqTrainer):
|
|
| 961 |
input_ids=generation_inputs,
|
| 962 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 963 |
generation_config=generation_config,
|
|
|
|
| 964 |
)
|
| 965 |
|
| 966 |
else:
|
| 967 |
generated_tokens = self.model.generate(
|
| 968 |
input_ids=generation_inputs,
|
| 969 |
generation_config=generation_config,
|
|
|
|
| 970 |
)
|
| 971 |
|
| 972 |
bs, source_len = inputs['input_ids'].shape
|
|
|
|
| 941 |
if "attention_mask" in inputs:
|
| 942 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 943 |
|
| 944 |
+
synced_gpus = gen_kwargs.pop("synced_gpus", False)
|
| 945 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 946 |
|
| 947 |
# prepare generation inputs
|
|
|
|
| 953 |
generated_tokens = self.model.generate(
|
| 954 |
input_ids=generation_inputs,
|
| 955 |
generation_config=generation_config,
|
| 956 |
+
synced_gpus=synced_gpus,
|
| 957 |
)
|
| 958 |
else:
|
| 959 |
generation_inputs = inputs[self.model.main_input_name]
|
|
|
|
| 963 |
input_ids=generation_inputs,
|
| 964 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 965 |
generation_config=generation_config,
|
| 966 |
+
synced_gpus=synced_gpus,
|
| 967 |
)
|
| 968 |
|
| 969 |
else:
|
| 970 |
generated_tokens = self.model.generate(
|
| 971 |
input_ids=generation_inputs,
|
| 972 |
generation_config=generation_config,
|
| 973 |
+
synced_gpus=synced_gpus,
|
| 974 |
)
|
| 975 |
|
| 976 |
bs, source_len = inputs['input_ids'].shape
|
root_gainlora/src/cl_trainer_gainlora_olora_llama.py
CHANGED
|
@@ -932,6 +932,7 @@ class GainLoRA_OLoRA_Trainer(Seq2SeqTrainer):
|
|
| 932 |
if "attention_mask" in inputs:
|
| 933 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 934 |
|
|
|
|
| 935 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 936 |
|
| 937 |
# prepare generation inputs
|
|
@@ -943,6 +944,7 @@ class GainLoRA_OLoRA_Trainer(Seq2SeqTrainer):
|
|
| 943 |
generated_tokens = self.model.generate(
|
| 944 |
input_ids=generation_inputs,
|
| 945 |
generation_config=generation_config,
|
|
|
|
| 946 |
)
|
| 947 |
else:
|
| 948 |
generation_inputs = inputs[self.model.main_input_name]
|
|
@@ -952,12 +954,14 @@ class GainLoRA_OLoRA_Trainer(Seq2SeqTrainer):
|
|
| 952 |
input_ids=generation_inputs,
|
| 953 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 954 |
generation_config=generation_config,
|
|
|
|
| 955 |
)
|
| 956 |
|
| 957 |
else:
|
| 958 |
generated_tokens = self.model.generate(
|
| 959 |
input_ids=generation_inputs,
|
| 960 |
generation_config=generation_config,
|
|
|
|
| 961 |
)
|
| 962 |
|
| 963 |
bs, source_len = inputs['input_ids'].shape
|
|
|
|
| 932 |
if "attention_mask" in inputs:
|
| 933 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 934 |
|
| 935 |
+
synced_gpus = gen_kwargs.pop("synced_gpus", False)
|
| 936 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 937 |
|
| 938 |
# prepare generation inputs
|
|
|
|
| 944 |
generated_tokens = self.model.generate(
|
| 945 |
input_ids=generation_inputs,
|
| 946 |
generation_config=generation_config,
|
| 947 |
+
synced_gpus=synced_gpus,
|
| 948 |
)
|
| 949 |
else:
|
| 950 |
generation_inputs = inputs[self.model.main_input_name]
|
|
|
|
| 954 |
input_ids=generation_inputs,
|
| 955 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 956 |
generation_config=generation_config,
|
| 957 |
+
synced_gpus=synced_gpus,
|
| 958 |
)
|
| 959 |
|
| 960 |
else:
|
| 961 |
generated_tokens = self.model.generate(
|
| 962 |
input_ids=generation_inputs,
|
| 963 |
generation_config=generation_config,
|
| 964 |
+
synced_gpus=synced_gpus,
|
| 965 |
)
|
| 966 |
|
| 967 |
bs, source_len = inputs['input_ids'].shape
|
root_gainlora/src/cl_trainer_inflora.py
CHANGED
|
@@ -705,6 +705,7 @@ class InfLoRATrainer(Seq2SeqTrainer):
|
|
| 705 |
if "attention_mask" in inputs:
|
| 706 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 707 |
|
|
|
|
| 708 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 709 |
|
| 710 |
# prepare generation inputs
|
|
@@ -716,6 +717,7 @@ class InfLoRATrainer(Seq2SeqTrainer):
|
|
| 716 |
generated_tokens = self.model.generate(
|
| 717 |
input_ids=generation_inputs,
|
| 718 |
generation_config=generation_config,
|
|
|
|
| 719 |
)
|
| 720 |
else:
|
| 721 |
generation_inputs = inputs[self.model.main_input_name]
|
|
@@ -725,12 +727,14 @@ class InfLoRATrainer(Seq2SeqTrainer):
|
|
| 725 |
input_ids=generation_inputs,
|
| 726 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 727 |
generation_config=generation_config,
|
|
|
|
| 728 |
)
|
| 729 |
|
| 730 |
else:
|
| 731 |
generated_tokens = self.model.generate(
|
| 732 |
input_ids=generation_inputs,
|
| 733 |
generation_config=generation_config,
|
|
|
|
| 734 |
)
|
| 735 |
|
| 736 |
bs, source_len = inputs['input_ids'].shape
|
|
|
|
| 705 |
if "attention_mask" in inputs:
|
| 706 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 707 |
|
| 708 |
+
synced_gpus = gen_kwargs.pop("synced_gpus", False)
|
| 709 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 710 |
|
| 711 |
# prepare generation inputs
|
|
|
|
| 717 |
generated_tokens = self.model.generate(
|
| 718 |
input_ids=generation_inputs,
|
| 719 |
generation_config=generation_config,
|
| 720 |
+
synced_gpus=synced_gpus,
|
| 721 |
)
|
| 722 |
else:
|
| 723 |
generation_inputs = inputs[self.model.main_input_name]
|
|
|
|
| 727 |
input_ids=generation_inputs,
|
| 728 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 729 |
generation_config=generation_config,
|
| 730 |
+
synced_gpus=synced_gpus,
|
| 731 |
)
|
| 732 |
|
| 733 |
else:
|
| 734 |
generated_tokens = self.model.generate(
|
| 735 |
input_ids=generation_inputs,
|
| 736 |
generation_config=generation_config,
|
| 737 |
+
synced_gpus=synced_gpus,
|
| 738 |
)
|
| 739 |
|
| 740 |
bs, source_len = inputs['input_ids'].shape
|
root_gainlora/src/cl_trainer_olora.py
CHANGED
|
@@ -547,6 +547,7 @@ class OLoRATrainer(Seq2SeqTrainer):
|
|
| 547 |
if "attention_mask" in inputs:
|
| 548 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 549 |
|
|
|
|
| 550 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 551 |
|
| 552 |
# prepare generation inputs
|
|
@@ -558,6 +559,7 @@ class OLoRATrainer(Seq2SeqTrainer):
|
|
| 558 |
generated_tokens = self.model.generate(
|
| 559 |
input_ids=generation_inputs,
|
| 560 |
generation_config=generation_config,
|
|
|
|
| 561 |
)
|
| 562 |
else:
|
| 563 |
generation_inputs = inputs[self.model.main_input_name]
|
|
@@ -567,12 +569,14 @@ class OLoRATrainer(Seq2SeqTrainer):
|
|
| 567 |
input_ids=generation_inputs,
|
| 568 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 569 |
generation_config=generation_config,
|
|
|
|
| 570 |
)
|
| 571 |
|
| 572 |
else:
|
| 573 |
generated_tokens = self.model.generate(
|
| 574 |
input_ids=generation_inputs,
|
| 575 |
generation_config=generation_config,
|
|
|
|
| 576 |
)
|
| 577 |
|
| 578 |
bs, source_len = inputs['input_ids'].shape
|
|
|
|
| 547 |
if "attention_mask" in inputs:
|
| 548 |
gen_kwargs["attention_mask"] = inputs.get("attention_mask", None)
|
| 549 |
|
| 550 |
+
synced_gpus = gen_kwargs.pop("synced_gpus", False)
|
| 551 |
generation_config = GenerationConfig(**gen_kwargs)
|
| 552 |
|
| 553 |
# prepare generation inputs
|
|
|
|
| 559 |
generated_tokens = self.model.generate(
|
| 560 |
input_ids=generation_inputs,
|
| 561 |
generation_config=generation_config,
|
| 562 |
+
synced_gpus=synced_gpus,
|
| 563 |
)
|
| 564 |
else:
|
| 565 |
generation_inputs = inputs[self.model.main_input_name]
|
|
|
|
| 569 |
input_ids=generation_inputs,
|
| 570 |
input_ids_wo_label=inputs["input_ids_wo_label"],
|
| 571 |
generation_config=generation_config,
|
| 572 |
+
synced_gpus=synced_gpus,
|
| 573 |
)
|
| 574 |
|
| 575 |
else:
|
| 576 |
generated_tokens = self.model.generate(
|
| 577 |
input_ids=generation_inputs,
|
| 578 |
generation_config=generation_config,
|
| 579 |
+
synced_gpus=synced_gpus,
|
| 580 |
)
|
| 581 |
|
| 582 |
bs, source_len = inputs['input_ids'].shape
|