unslothai / unsloth

Finetune Llama 3.2, Mistral, Phi, Qwen & Gemma LLMs 2-5x faster with 80% less memory
https://unsloth.ai
Apache License 2.0
17.94k stars 1.24k forks source link

Jinja2 Fails at 50% #433

Closed pfifo closed 1 week ago

pfifo commented 6 months ago

So while I was trying to train a model, at exactly the halfway point, I encountered and error because Jinja2 was not installed. While this is an easily resolvable error, the fact that it happened to begin with is the real issue. I think under ideal circumstances that the library should be installed during the unsloth installation procedure. And dependencies preferably checked and validated during runtime at program startup.

Prior to this run I pulled an update from github as per the instructions at https://github.com/unslothai/unsloth/wiki which do indeed mention "without dependency updates" which I wrongly assumed to mean "You dont have to ever update dependencies under any circumstance when updating unsloth" This sentiment was compounded by the lack of a section giving instructions for updating dependencies. It is my recommendation to add information to the wiki detailing how to update dependencies, as well as information about how to determine if dependency updates are needed.

While I do understand that I can read every line of the source code for unsloth and all of its dependencies in order to guide myself in the proper direction when using unsloth, I very much feel that over all desire of unsloth is to abstract the details away from the user and to provide a useful, easy to use tool suitable for end use. Therefore providing the proposed changes seems to be a good step toward achieving that goal and is the reason I am reporting this as an issue.

{'loss': 1.8562, 'grad_norm': 2.403313636779785, 'learning_rate': 0.00010110552763819097, 'epoch': 2.48}                                                                                                   
{'loss': 1.8265, 'grad_norm': 2.4125723838806152, 'learning_rate': 0.00010090452261306533, 'epoch': 2.49}                                                                                                  
{'loss': 1.8723, 'grad_norm': 2.2457594871520996, 'learning_rate': 0.0001007035175879397, 'epoch': 2.5}                                                                                                    
{'loss': 1.798, 'grad_norm': 2.0121476650238037, 'learning_rate': 0.00010050251256281407, 'epoch': 2.5}                                                                                                    
{'eval_loss': 3.009955406188965, 'eval_runtime': 41.0613, 'eval_samples_per_second': 9.742, 'eval_steps_per_second': 2.435, 'epoch': 2.5}                                                                  
 50%|███████████████████████████████████████████████████████████████████████████████▌                                                                               | 500/1000 [1:48:22<1:10:30,  8.46s/itTraceback (most recent call last):                                                                                                                                                                          
  File "~/unsloth/text-trainer-with-eval.py", line 87, in <module>
    trainer_stats = trainer.train()
  File "~/.local/lib/python3.10/site-packages/trl/trainer/sft_trainer.py", line 361, in train
    output = super().train(*args, **kwargs)
  File "~/.local/lib/python3.10/site-packages/transformers/trainer.py", line 1859, in train
    return inner_training_loop(
  File "<string>", line 436, in _fast_inner_training_loop
  File "~/.local/lib/python3.10/site-packages/transformers/trainer.py", line 2673, in _maybe_log_save_evaluate
    self._save_checkpoint(model, trial, metrics=metrics)
  File "~/.local/lib/python3.10/site-packages/transformers/trainer.py", line 2752, in _save_checkpoint
    self.save_model(output_dir, _internal_call=True)
  File "~/.local/lib/python3.10/site-packages/transformers/trainer.py", line 3252, in save_model
    self._save(output_dir)
  File "~/.local/lib/python3.10/site-packages/transformers/trainer.py", line 3327, in _save
    self.model.save_pretrained(
  File "~/.local/lib/python3.10/site-packages/peft/peft_model.py", line 213, in save_pretrained
    self.create_or_update_model_card(save_directory)
  File "~/.local/lib/python3.10/site-packages/peft/peft_model.py", line 821, in create_or_update_model_card
    card = ModelCard.load(filename) if os.path.exists(filename) else ModelCard.from_template(ModelCardData())
  File "~/.local/lib/python3.10/site-packages/huggingface_hub/repocard.py", line 414, in from_template
    return super().from_template(card_data, template_path, template_str, **template_kwargs)
  File "~/.local/lib/python3.10/site-packages/huggingface_hub/repocard.py", line 319, in from_template
    raise ImportError(
ImportError: Using RepoCard.from_template requires Jinja2 to be installed. Please install it with `pip install Jinja2`.
danielhanchen commented 6 months ago

Oh nice catch!! Did not know about Jinja2 - thanks for that - will add it in!

shimmyshimmer commented 1 week ago

Should work now hopefully! @pfifo