in-context-learning-2024 / in-context

5 stars 1 forks source link

Quickstart

Set up your environment with:

conda init zsh
conda env create -f environment.yaml
conda activate in-context-learning

Alternatively, you can instantiate a codespace (docs) that automagically does the above!

Run a training run specified by <config_file> with:

python src/ --config conf/train/<config_file>.yml

Resume a training run specified by <config_file> starting from <run_id>/<checkpoint_file> with:

python src/ --config conf/train/<config_file>.yml --resume models/<run_id>/<checkpoint_file>

Extending this repo

We follow the following flow for objects in this repository: ![image of the flow map](<readme_assets/flow map.png>)

Initializing a FunctionClass or ContextModel passes the dictionary parsed directly from yaml as arguments. We recommend reading examples for your respective function class in conf/

Make sure to initialize your parent class with super().__init__(...) in your __init__ routine for your custom FunctionClass or ContextModel. Omitting this can result in unexpected (and currently unchecked) errors!

We try to make it easy to contribute by adding models or function classes:


Adding Models

We wrap all sequence architectures and baselines as ContextModels. The order of calls against a ContextModel is as follows:

ContextModels thus have only two required methods:

In addition, we require both .context_length: int and .name: str to be set for evaluation and visualization.

To use your context model, add an identifier to src/models/__init__.py and refer to it as type: <your identifier> in yaml. Examples are in conf/include/models/

Adding Hybrid blocks:

We also provide an abstraction to compose hybrid architectures as a collection of blocks. The currently supported blocks are in src/models/hybrid.py. To add a block, add an identifier to SUPPORTED_BLOCKS in src/models/hybrid.py and an entry to MAPPING in the function SPEC_TO_MODULE in the same file. To pass a value to the configuration fed into your new block, just specify it as a key/value pair in your model: mapping in YAML. Examples of this are in conf/include/models/composed.yml, under defs -> base.


Adding Function Classes

We take the approach of framing each function class as an iterator, where the boilerplate of making the iterator work for our training scheme (ContextTrainer) is implemented for you. The order of calls against a FunctionClass is as follows:

FunctionClasses thus have three methods you need to implement:

In addition, you need to export your function class in src/function_classes/__init__.py

To use your function class, you can specify the key you specified in src/function_classes/__init__.py as type: <that key> in a training yaml configuration. Examples are in conf/train/