Modalities / modalities

Modalities, a PyTorch-native framework for distributed and reproducible foundation model training.
MIT License
61 stars 5 forks source link

Instruction-tuning Support #196

Open lllAlexanderlll opened 2 months ago

lllAlexanderlll commented 2 months ago

What does this PR do?

This PR adds support for instruction tuning, by

  1. Introducing a new entry point data apply_chat_template --config_file_path config_files/training/config_lorem_ipsum_sft.yaml which takes a instruction-dataset and converts the structured conversations into a single prompt by applying the chat template given as jinja2 template string within the config. Here, we also include indicator tokens to mark what the system utterances are.
  2. In modalities training entry point you can now wrap the collate function by a "LossMaskingCollateFn", which first executes the wrapped collate function and then applies loss masking on each target as specified in the config. This allows to only include tokens that are part of the assistant answer into the loss, so that the model learns to act as helpful assistant.
  3. Modifiy the PackedMemMapDatasetContinuous to allow not to re-use the last target token, as this is not wanted in instruction-tuning where we apply truncation and packing.

General Changes

Breaking Changes

Checklist before submitting final PR

lllAlexanderlll commented 2 months ago

Please merge the fix for main, so that the tests run all through in main first, by merging in PR #195

lllAlexanderlll commented 2 months ago

Added e2e test and a new feature request #210