Tasks
Tasks define data and model usage.
They provide a simple interface for swapping backbones, adapters, and data without any code changes, enabling rapid and reproducible experimentation.
They are specified with the --model
argument in the CLI or in the model
section of a configuration file.
Tasks automatically configure backbones and adapters for training with mgen fit
, evaluation with mgen test/validate
, and inference with mgen predict
.
They cover a range of use-cases for information extraction, domain adaptation, supervised prediction, generative modeling, and zero-shot applications.
This reference overviews the available no-code tasks for finetuning and inference. If you would like to develop new tasks, see Experiment Design.
# Example Task Configuration
model:
class_path: SequenceClassification
init_args:
backbone:
class_path: aido_dna_7b
init_args:
use_peft: true
lora_r: 16
lora_alpha: 32
lora_dropout: 0.1
adapter:
class_path: modelgenerator.adapters.MLPPoolAdapter
init_args:
pooling: mean_pooling
hidden_sizes:
- 512
- 256
bias: true
dropout: 0.1
dropout_in_middle: false
optimizer:
class_path: torch.optim.AdamW
init_args:
lr: 1e-4
lr_scheduler:
class_path: torch.optim.lr_scheduler.StepLR
init_args:
step_size: 1
gamma: 0.1
data:
...
trainer:
...
Note: Adapters and Backbones are typed as
Callables
, since some args are reserved to be automatically configured within the task. As a general rule, positional arguments are reserved while keyword arguments are free to use. For example, the backbone, adapter, optimizer, and lr_scheduler can be configured as
Extract
modelgenerator.tasks.Embed
Bases: TaskInterface
Task for getting embeddings from a pretrained backbone. This task is used only for inference.
Note
Must be used with PredictionWriter. Embeddings are stored under "predictions".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
**kwargs
|
Additional keyword arguments for the parent class.
|
{}
|
modelgenerator.tasks.Inference
Bases: MLM
Task for performing inference with a pretrained backbone end-to-end, including the backbone's original adapter.
Note
Must be used with PredictionWriter. Model outputs are stored under "predictions".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
use_legacy_adapter
|
bool
|
Whether to use the adapter from the backbone (HF head support). Warning: This is not supported for all tasks and will be depreciated in the future. |
True
|
**kwargs
|
Additional arguments passed to the parent class. |
{}
|
Adapt
modelgenerator.tasks.MLM
Bases: TaskInterface
Task for performing masked language modeling (MLM) with a pretrained backbone. Can be used to train from scratch or for domain adaptation. Uses the MLMDataModule. Evaluates in terms of reconstruction accuracy on all tokens and cross-entropy loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
use_legacy_adapter
|
bool
|
Whether to use the adapter from the backbone (HF head support). Warning: This is not supported for all tasks and will be depreciated in the future. |
True
|
**kwargs
|
Additional arguments passed to the parent class. |
{}
|
modelgenerator.tasks.ConditionalMLM
Bases: TaskInterface
Task for masked language modeling with extra condition inputs. Evaluates in terms of reconstruction accuracy on all tokens and cross-entropy loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
adapter
|
Optional[Callable[[int, int, int, Module], ConditionalGenerationAdapter]]
|
A ConditionalGenerationAdapter for the model. |
ConditionalLMAdapter
|
use_legacy_adapter
|
bool
|
Whether to use the pre-trained legacy adapter within the conditional decoder. |
True
|
condition_dim
|
int
|
The dimension of the condition. |
1
|
**kwargs
|
Additional arguments passed to the parent class. |
{}
|
Predict
modelgenerator.tasks.SequenceClassification
Bases: TaskInterface
Task for fine-tuning a sequence model for classification. Evaluates in terms of accuracy, F1 score, Matthews correlation coefficient (MCC), and AUROC.
Note
Supports binary, multiclass, and binary multi-label classification tasks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
adapter
|
Optional[Callable[[int, int], SequenceAdapter]]
|
A SequenceAdapter for the model. |
LinearCLSAdapter
|
n_classes
|
int
|
The number of classes in the classification task. |
2
|
multilabel
|
bool
|
Indicate whether multiple labels can be positive, turning this into a multi-way binary classification task. |
False
|
**kwargs
|
Additional arguments passed to the parent class. |
{}
|
modelgenerator.tasks.TokenClassification
Bases: SequenceClassification
Task for fine-tuning a model for token-wise classification. Evaluates in terms of accuracy, F1 score, Matthews correlation coefficient (MCC), and AUROC.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
adapter
|
Optional[Callable[[int, int], TokenAdapter]]
|
A TokenAdapter for the model. |
LinearAdapter
|
n_classes
|
int
|
The number of classes in the classification task. |
2
|
**kwargs
|
Additional keyword arguments for the parent class. |
{}
|
Attributes:
Name | Type | Description |
---|---|---|
legacy_adapter_type |
LegacyAdapterType
|
The LegacyAdapterType.TOKEN_CLS legacy adapter. |
modelgenerator.tasks.PairwiseTokenClassification
Bases: SequenceClassification
Task for fine-tuning a model for pairwise token classification. Evaluates in terms of accuracy, F1 score, Matthews correlation coefficient (MCC), AUROC, and top-k accuracy for k=2,5,10.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
adapter
|
Optional[Callable[[int, int], TokenAdapter]]
|
A TokenAdapter for the model. |
LinearAdapter
|
adapter_dim_multiplier
|
int
|
The multiplier for the adapter dimension. Defaults to 2. |
2
|
**kwargs
|
Additional keyword arguments for the parent class. |
{}
|
Attributes:
Name | Type | Description |
---|---|---|
legacy_adapter_type |
LegacyAdapterType
|
The LegacyAdapterType.TOKEN_CLS legacy adapter. |
modelgenerator.tasks.MMSequenceRegression
Bases: TaskInterface
Task for fine-tuning multiple models on single-/multi-task regression. Evaluates in terms of mean absolute error, mean squared error, R2 score, Pearson correlation, and Spearman correlation.
Note
Supports any combination of DNA, RNA and protein backbones
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
backbone1
|
BackboneCallable
|
A second pretrained backbone from the modelgenerator library. |
required |
backbone2
|
Optional[BackboneCallable]
|
An optional third pretrained backbone from the modelgenerator library. |
None
|
backbone_order
|
list
|
A list of data columns in order of the backbones. Defaults to ["dna_seq", "rna_seq", "protein_seq"]. |
['dna_seq', 'rna_seq']
|
adapter
|
Optional[Callable[[int, int, int, int], FusionAdapter]]
|
A callable that returns a FusionAdapter. |
MMFusionTokenAdapter
|
num_outputs
|
int
|
The number of outputs for the regression task. |
1
|
loss_func
|
Callable[..., Module]
|
A callable that returns a loss function. |
MSELoss
|
**kwargs
|
Additional arguments passed to the parent class. |
{}
|
Generate
modelgenerator.tasks.Diffusion
Bases: TaskInterface
Masked Diffusion Language Modeling training and generation on sequences. Evaluates in terms of reconstruction accuracy on masked tokens and cross-entropy loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
adapter
|
Optional[Callable[[int, int], TokenAdapter]]
|
A TokenAdapter for the model. |
None
|
use_legacy_adapter
|
bool
|
Whether to use the adapter from the backbone (HF head support). Warning: This is not supported for all tasks and will be depreciated in the future. |
True
|
sample_seq
|
bool
|
Whether to sample tokens during denoising, instead of always using the most likely token. |
False
|
num_denoise_steps
|
int
|
Granularity of the denoising process. Less steps makes fewer forward passes and denoises more aggressively. |
4
|
sampling_temperature
|
float
|
The temperature for sampling tokens, if sample_seq is True. |
1.0
|
normalize_posterior_weights
|
bool
|
Whether to normalize posterior weights. Experimental feature to help training stability. |
False
|
verbose
|
bool
|
Print while denoising (warning: fun to watch). |
False
|
**kwargs
|
Additional arguments passed to the parent class. |
{}
|
modelgenerator.tasks.ConditionalDiffusion
Bases: Diffusion
Task for masked diffusion language modeling with extra condition inputs. Evaluates in terms of reconstruction accuracy on masked tokens and cross-entropy loss.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
adapter
|
Optional[Callable[[int, int, int, Module], ConditionalGenerationAdapter]]
|
A ConditionalGenerationAdapter for the model. |
ConditionalLMAdapter
|
use_legacy_adapter
|
bool
|
Whether to use the pre-trained legacy adapter within the conditional decoder. |
True
|
condition_dim
|
int
|
The dimension of the condition. |
1
|
**kwargs
|
Additional arguments passed to the parent class. |
{}
|
Zero-Shot
modelgenerator.tasks.ZeroshotPredictionDiff
Bases: TaskInterface
Task for zero-shot prediction with a languange model that produces token logits. Computes the log-likelihood difference between probability of ref and alt at the mutated position. Evaluates in terms of AUROC and AUPRC.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
**kwargs
|
Additional keyword arguments for the parent class.
|
{}
|
modelgenerator.tasks.ZeroshotPredictionDistance
Bases: TaskInterface
Task for zero-shot prediction with a model that produces embeddings. Computes the L1 and L2 distance between the reference and mutated sequence embeddings. Evaluates in terms of AUROC and AUPRC of the embedding distance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backbone
|
BackboneCallable
|
A pretrained backbone from the modelgenerator library. |
required |
all_hidden_states
|
bool
|
Whether to run the test on all available hidden layers. Defaults to False, only using the last layer. |
False
|
shared_ref
|
bool
|
Whether to use a shared reference sequence to accelerate zero-shot computation. Uses a separate reference sequence for each mutated sequence by default. |
False
|
**kwargs
|
Additional keyword arguments for the parent class.
|
{}
|