-
Notifications
You must be signed in to change notification settings - Fork 44
[QEff Finetune]: Adding steps about how to fine tune on any custom dataset. #381
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
Changes from all commits
e757ab8
bae75d2
05a385a
155bb77
6262009
25a2ac5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,4 +64,44 @@ to visualise the data, | |
|
||
```python | ||
tensorboard --logdir runs/<file> --bind_all | ||
``` | ||
``` | ||
|
||
## Some features/functionalities of fine-tuning stack: | ||
1) Gradient accumulation: By default, gradient accumulation happens for 4 steps. To update this value, command line argument gradient_accumulation_steps has to be passed. (Example: '--gradient_accumulation_steps 8') | ||
2) Gradient Checkpointing: By default, gradient checkpointing is disabled. To enable it, command line argument gradient_accumulation_steps has to be passed. | ||
|
||
## Fine-Tuning on custom dataset | ||
|
||
To run fine tuning for any user specific dataset, prepare the dataset using the following steps: | ||
|
||
1) Create a directory named 'dataset' inside efficient-transformers. | ||
2) Inside this directory, create a file named 'custom_dataset.py'. | ||
3) Inside the newly created efficient-transformers/dataset/custom_dataset.py, define a function named 'get_custom_dataset'. | ||
4) get_custom_dataset() should have following 4 parameters: dataset_config, tokenizer, split, context_length. | ||
5) Inside get_custom_dataset(), user needs to apply prompt and tokenize the dataset accordingly. Please refer the below template on how to define get_custom_dataset(). | ||
6) For examples, please refer python files present in [dataset](https://github.com/quic/efficient-transformers/tree/main/QEfficient/finetune/dataset). In case of Samsum dataset, get_preprocessed_samsum() of efficient-transformers/QEfficient/finetune/dataset/samsum_dataset.py is called. | ||
7) In [dataset_config.py](https://github.com/quic/efficient-transformers/blob/main/QEfficient/finetune/configs/dataset_config.py), for custom_dataset class, pass the appropriate value for train_split and test_split. As an alternative, these values can be passed as command line arguments as well with the finetune command. For example "--train_split train". | ||
8) While running fine tuning, pass argument "-–dataset custom_dataset" to finetune on custom dataset. | ||
|
||
Template for get_custom_dataset() to be defined inside efficient-transformers/dataset/custom_dataset.py is as follows: | ||
|
||
```python | ||
def get_custom_dataset(dataset_config, tokenizer, split, context_length=None): | ||
|
||
# load dataset | ||
# based on split, retrieve only the specific portion of the dataset (train or eval) either here or at the last | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add one more comment as "Define a prompt template" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's already there. ( # define prompt) |
||
|
||
def apply_prompt_template(): | ||
# transform the passed datapoint by applying the prompt on it | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some comment as "Convert the raw input into format as per the template defined earlier." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
|
||
def tokenize(): | ||
# tokenize the passed datapoint | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some comment as "Implement tokenization and prepare inputs for the training." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added. |
||
|
||
# define the prompt | ||
# call apply_prompt_template() for each data point: | ||
# dataset = dataset.map(apply_prompt_template ,<other args>) | ||
# call tokenize() for each data point: | ||
# dataset = dataset.map(tokenize, <other args>) | ||
|
||
return dataset | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should include details on how we use gradient accumulation, how the dataset is shuffled, how activation checkpointing is enabled in separate sections.
In custom dataset, add a point that if any user wants to use these, refer xyz section
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the section explaining how to use gradient accumulation and gradient checkpointing.
For single SOC, we are not doing any shuffling of data. By default, it is False.
For DDP, in case of sorting, shuffling is set to false.
For DDP without sorting, shuffling was set to True. Made it False to sync it up with single SOC run and also to be able to use 'resume finetuning from between' feature. this was not caught earlier because by default we run DDP with sorting only.
Hence, didn't add any information about shuffling in the doc.