Quick fixes (#106)

* Fix tokenizer, dropout, bias for LoRA

* Update loader.py

* Fix LoRA downcasting

* Update _utils.py

* Saving to GGUF

* fix

* colab_quantize_to_gguf

* move save modules

* save module

* Update __init__.py

* Update save.py

* Temp downgrade due to TRL issue

* Fix up bugs

* Faster saving + other changes

* Update llama.py

* Saving modules

* spelling

* Update llama.py

* Update save.py

* Update save.py

* Update loader.py

* Update llama.py

* patch saving

* Update save.py

* Update save.py

* Update save.py

* patch saving

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* original_model

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* saving to RAM leakage?

* Update save.py

* new_save_directory

* Update save.py

* Update save.py

* Update save.py

* Update save.py

* Update pyproject.toml

* Update pyproject.toml

* Update pyproject.toml

* Quick fixes

* Update llama.py

* Update llama.py

* Update dpo.py

* Update dpo.py

* Update llama.py

* Update save.py

* getattr

* RSLoRA and LoftQ direct support

* Update llama.py

* Update llama.py

* Update llama.py

* Fix DPO + GGUF
This commit is contained in:
Daniel Han 2024-01-20 04:25:06 +11:00 committed by GitHub
commit 12e75c93d0
4 changed files with 33 additions and 26 deletions

View file

@ -242,7 +242,17 @@ def LoraLayer_update_layer(self, adapter_name, r, lora_alpha, lora_dropout, init
self.scaling[adapter_name] = lora_alpha / r
if init_lora_weights == "loftq":
# We manually check for PEFT
if not hasattr(self, "loftq_init"):
import peft
raise RuntimeError(
f"Unsloth: Your PEFT version of {peft.__version__} does not support LoftQ init.\n"\
"Please install PEFT 0.7.2 or higher.\n"\
"You can also install from source: `pip install git+https://github.com/huggingface/peft.git"
)
pass
self.loftq_init(adapter_name)
elif init_lora_weights:
self.reset_lora_parameters(adapter_name, init_lora_weights)

View file

@ -28,6 +28,7 @@ DPOTrainer_metrics = [
"logits/rejected",
"logits/chosen",
]
set_DPOTrainer_metrics = frozenset(DPOTrainer_metrics)
def NotebookProgressCallback_on_train_begin(self, args, state, control, **kwargs):
@ -47,16 +48,7 @@ def NotebookProgressCallback_on_log(self, args, state, control, logs=None, **kwa
if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:
values = {"Training Loss": logs["loss"]}
for metric in DPOTrainer_metrics:
if metric in logs:
values[metric.replace("/", " / ")] = logs[metric]
else:
# Maybe not a DPO Trainer anymore? Redo the tracker
column_names = [self.first_column] + ["Training Loss"]
if args.evaluation_strategy != IntervalStrategy.NO:
column_names.append("Validation Loss")
self.training_tracker = NotebookTrainingTracker(state.max_steps, column_names)
break
pass
values[metric.replace("/", " / ")] = logs[metric]
pass
# First column is necessarily Step since we're not in epoch eval strategy
values["Step"] = state.global_step
@ -76,10 +68,16 @@ def NotebookTrainingTracker_write_line(self, values):
self.inner_table = [list(values.keys()), list(values.values())]
else:
columns = self.inner_table[0]
print(columns)
for key in values.keys():
if key not in columns:
columns.append(key)
new_values = {}
for key, value in values.items():
lowered = key.lower()
if lowered in set_DPOTrainer_metrics:
new_values[lowered.replace("/", " / ")] = value
else:
new_values[key] = value
pass
values = new_values
self.inner_table[0] = columns
if len(self.inner_table) > 1:
last_values = self.inner_table[-1]
@ -104,7 +102,7 @@ pass
def PatchDPOTrainer():
# Patch DPO notebook printing
# NotebookTrainingTracker.write_line = NotebookTrainingTracker_write_line
NotebookTrainingTracker.write_line = NotebookTrainingTracker_write_line
from transformers.trainer import DEFAULT_PROGRESS_CALLBACK
DEFAULT_PROGRESS_CALLBACK.on_train_begin = NotebookProgressCallback_on_train_begin
DEFAULT_PROGRESS_CALLBACK.on_log = NotebookProgressCallback_on_log

View file

@ -912,14 +912,13 @@ class FastLlamaModel:
assert(type(use_rslora) is bool)
if use_rslora:
if not SUPPORTS_RSLORA:
# We do it ourselves!
new_alpha = lora_alpha / (r**0.5)
# We manually check for PEFT
import peft
logger.warning_once(
f"Unsloth: Your PEFT version of {peft.__version__} (0.7.2 needed) does not support `use_rslora` natively.\n"\
f"But, we do it ourselves by setting `alpha = {new_alpha}.`"
raise RuntimeError(
f"Unsloth: Your PEFT version of {peft.__version__} does not support `use_rslora`.\n"\
"Please install PEFT 0.7.2 or higher.\n"\
"You can also install from source: `pip install git+https://github.com/huggingface/peft.git"
)
lora_alpha = new_alpha
pass
pass

View file

@ -555,7 +555,7 @@ def unsloth_push_to_hub_merged(
self,
repo_id : str,
tokenizer = None,
save_method : str = "merged_16bit", # ["lora", "merged_16bit", "merged_4bit"]
save_method : str = "merged_16bit", # ["lora", "merged_16bit", "merged_4bit"]
use_temp_dir : Optional[bool] = None,
commit_message : Optional[str] = None,
private : Optional[bool] = None,
@ -601,7 +601,7 @@ def unsloth_save_pretrained_gguf(
self,
save_directory : Union[str, os.PathLike],
tokenizer = None,
quantization_method : str = "fast_quantized",
quantization_method : str = "fast_quantized",
push_to_hub : bool = False,
token : Optional[Union[str, bool]] = None,
is_main_process : bool = True,
@ -649,7 +649,7 @@ def unsloth_save_pretrained_gguf(
arguments["push_to_hub"] = False # We save ourselves
arguments["save_method"] = "merged_16bit" # Must be 16bit
del arguments["self"]
del arguments["quantization"]
del arguments["quantization_method"]
# Non blocking install GGUF first
git_clone = install_llama_cpp_clone_non_blocking()
@ -699,7 +699,7 @@ def unsloth_push_to_hub_gguf(
self,
repo_id : str,
tokenizer = None,
quantization_method : str = "fast_quantized",
quantization_method : str = "fast_quantized",
use_temp_dir : Optional[bool] = None,
commit_message : Optional[str] = None,
private : Optional[bool] = None,
@ -749,7 +749,7 @@ def unsloth_push_to_hub_gguf(
arguments["save_method"] = "merged_16bit" # Must be 16bit
del arguments["self"]
del arguments["repo_id"]
del arguments["quantization"]
del arguments["quantization_method"]
# Non blocking install GGUF first
git_clone = install_llama_cpp_clone_non_blocking()