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

Add NEFTune implementation for Noised Embedding Instruction Fine-Tuning support #3744

Merged
merged 10 commits into from
Nov 23, 2023

Conversation

arnavgarg1
Copy link
Contributor

@arnavgarg1 arnavgarg1 commented Oct 20, 2023

This PR adds an implementation of the original NEFTune paper to add noise to the embedding outputs at train time. Empirical evidence suggests that this improves model performance by up to 35% and reduces overfitting.

To use this in Ludwig with LLMs, just set neftune_noise_alpha in the model_parameters section of your LLM model config to a non-zero value.

model_type: llm
base_model: meta-llama/Llama-2-7b-hf
model_parameters:
    neftune_noise_alpha: 5

Implentation

I implemented this is as a forward hook that gets added to the embedding layer once we're inside the trainer (well after the model is already instantiated) and removed at the end of training. The base class abstraction allows us to modify the behavior in custom ways for this hook as well as future hooks, including using backward or forward hooks, or even not removing the hook at the end of training (if desired).

@arnavgarg1 arnavgarg1 changed the title WIP: Add NEFTune Noise Embeddings for Instruction Fine-Tuning WIP: Add NEFTune based Embedding Noise for Instruction Fine-Tuning Oct 20, 2023
@github-actions
Copy link

github-actions bot commented Oct 20, 2023

Unit Test Results

  6 files  ±0    6 suites  ±0   14m 23s ⏱️ ±0s
12 tests ±0    9 ✔️ ±0    3 💤 ±0  0 ±0 
60 runs  ±0  42 ✔️ ±0  18 💤 ±0  0 ±0 

Results for commit b7e32a1. ± Comparison against base commit 2f159b6.

♻️ This comment has been updated with latest results.

@arnavgarg1 arnavgarg1 marked this pull request as ready for review November 21, 2023 19:40
@arnavgarg1 arnavgarg1 changed the title WIP: Add NEFTune based Embedding Noise for Instruction Fine-Tuning Add NEFTune based Embedding Noise for Instruction Fine-Tuning Nov 21, 2023
@arnavgarg1 arnavgarg1 changed the title Add NEFTune based Embedding Noise for Instruction Fine-Tuning Add NEFTune implementation for Noised Embedding Instruction Fine-Tuning support Nov 21, 2023
Copy link
Collaborator

@tgaddair tgaddair left a comment

Choose a reason for hiding this comment

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

Looks great! Just a couple nits.

ludwig/modules/training_hooks.py Show resolved Hide resolved
ludwig/modules/training_hooks.py Outdated Show resolved Hide resolved
ludwig/modules/training_hooks.py Outdated Show resolved Hide resolved
@arnavgarg1 arnavgarg1 merged commit efda117 into master Nov 23, 2023
17 checks passed
@arnavgarg1 arnavgarg1 deleted the neftune branch November 23, 2023 00:21
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.

2 participants