Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Lora finetuning script #1179

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pattplatt
Copy link

Added code to check if val data is longer than train data which prevents errors if this case occurs. Also added code that allows to use of the validation data in model training except for the example prompt. These two changes could also be implemented in the other finetuning/training scripts.

…nts errors if this case occurs, also added feature to use val data in model training
litgpt/finetune/lora.py Show resolved Hide resolved
litgpt/finetune/lora.py Show resolved Hide resolved
Comment on lines +350 to +355
rand = random.randint(0, 50)
try:
instruction = val_dataloader.dataset.data[rand]["instruction"]
except Exception as e:
print(f"Import of validation data failed: {e}")
instruction = "Recommend a movie for me to watch during the weekend and explain the reason."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can understand the desire for not hardcoding the instruction. On the other hand, always using the same one is useful to observe progress in the continuation.

Maybe it's best to drop this bit entirely instead

Copy link
Author

@pattplatt pattplatt Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought was that it is helpful to get a feeling if the model generalizes well over the validation data. If you always have the same prompt you can't really tell, or am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this as a preference without no right or wrong. I'll defer this decision to the folks who finetune the most: @rasbt and @awaelchli

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say for the generalization aspect, we already calculate the loss over the validation set. The fixed prompt here is more of a small visual check, and I do think it helps having it the same prompt.

We could potentially do it like this:

  • by default select a random validation set instruction (like we do now) and keep it constant over the training for visual purposes
  • let users override this in the config perhaps via a "rotate" argument or so. Where validation_instruction: str = "fixed" defaults to the current behavior but that might be overkill

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me when this happens. Everytime the validation function is called?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add what Sebastian said I would say that we can't tell very well from a single example by how much the model is improving. Whether it is a sample from the dataset or one we provide doesn't matter much. It's there as a sanity check to make sure the model eventually starts following instructions and adopting the prompt template. I am in favor of keeping it simple.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me when this happens. Everytime the validation function is called?

I'd say if we were to add the rotation, that would be also done every eval.interval steps (the default is 100) (which currently includes both calculating the loss over the entire validation set and then also using the one example prompt/instruction for a quick visual sanity check that the model generates coherent text.)

litgpt/finetune/lora.py Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants