TrainerSuite
Bases: ABC
Orchestrate one trainer instance per unordered pair of target classes.
Example
suite = PositiveTrainerSuite( TextPredictionTrainer, model="bert-base-uncased", args=train_args, data=training_df, target_classes=["positive", "negative", "neutral"], run_id="feature_suite", )
suite.train(use_cache=True) suite.plot_similarity_heatmap(measure="cosine")
Source code in gradiend/trainer/suite/base.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
_input_pair_definitions
instance-attribute
_input_pair_definitions = _normalize_pair_definitions(pair_definitions, pair_id_fn=pair_id_fn or _default_child_id, pair_label_fn=pair_label_fn or _default_child_label)
__getattr__
Source code in gradiend/trainer/suite/base.py
__iter__
__len__
_build_annotation_trainer
Source code in gradiend/trainer/suite/base.py
_build_child_trainer
Source code in gradiend/trainer/suite/base.py
_child_run_id
_effective_label_mapping
Source code in gradiend/trainer/suite/base.py
_load_eval_model
Source code in gradiend/trainer/suite/base.py
_prepare_child_trainer_kwargs
_release_model_refs
Source code in gradiend/trainer/suite/base.py
_resolve_pair_definitions
_resolve_suite_dispersion
_resolve_suite_seed_selection
_retain_model
Source code in gradiend/trainer/suite/base.py
_suite_oom_error
Source code in gradiend/trainer/suite/base.py
_transform_pretty_groups
Source code in gradiend/trainer/suite/base.py
_validate_shared_model_compatibility
Source code in gradiend/trainer/suite/base.py
annotate_data
Annotate the full shared suite dataset once using the shared base model and full class set.
This intentionally does not run one annotation pass per child trainer because all suite children share the same base model and underlying data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to |
{}
|
Source code in gradiend/trainer/suite/base.py
call
Call a method on every child trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
Name of the child trainer method to call. |
required |
*args
|
Any
|
Positional arguments forwarded to the child method. |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to the child method. |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict mapping |
Source code in gradiend/trainer/suite/base.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
clear_model_cache
Source code in gradiend/trainer/suite/base.py
compute_grouped_similarity_matrices
Compute pairwise similarity matrices grouped by model component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_mapping
|
Optional[Dict[str, str]]
|
Optional child-id to display-label mapping. |
None
|
use_cache
|
bool
|
Forwarded to child model loading. |
True
|
**kwargs
|
Any
|
Forwarded to grouped similarity computation. |
{}
|
Source code in gradiend/trainer/suite/base.py
compute_similarity_matrix
Compute pairwise similarity across child GRADIEND models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_mapping
|
Optional[Dict[str, str]]
|
Optional child-id to display-label mapping. |
None
|
use_cache
|
bool
|
Forwarded to child model loading. |
True
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Source code in gradiend/trainer/suite/base.py
compute_trainer_pair_encoding_matrix
compute_trainer_pair_encoding_matrix(*, label_mapping=None, full_eval=True, encoder_eval='auto', allow_incomplete=False, **kwargs)
Compute trainer-pair encoding matrix for positive-pair suites.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_mapping
|
Optional[Dict[str, str]]
|
Optional child-id to display-label mapping. |
None
|
full_eval
|
bool
|
Whether child encoder evaluation should include all available transitions. |
True
|
encoder_eval
|
str
|
Encoder evaluation policy: |
'auto'
|
allow_incomplete
|
bool
|
If True, tolerate missing child encoder results. |
False
|
**kwargs
|
Any
|
Forwarded by subclasses to trainer-pair encoding computation. |
{}
|
Source code in gradiend/trainer/suite/base.py
evaluate
Evaluate every child trainer and return child_id -> result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to child |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to child |
{}
|
Source code in gradiend/trainer/suite/base.py
evaluate_decoder
Run decoder evaluation for every child trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to child |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to child |
{}
|
Source code in gradiend/trainer/suite/base.py
evaluate_encoder
Run encoder evaluation for every child trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to child |
()
|
full_eval
|
Optional[bool]
|
If True, include non-target transitions by default. When
omitted, defaults to True for |
None
|
**kwargs
|
Any
|
Keyword arguments forwarded to child |
{}
|
Source code in gradiend/trainer/suite/base.py
get_models
get_models(*, label_mapping=None, load_missing=True, use_cache=True, seed_selection=None, gradiend_only=False)
Load suite child models for comparison or plotting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_mapping
|
Optional[Dict[str, str]]
|
Optional child-id to display-label mapping. |
None
|
load_missing
|
bool
|
If True, load models not already retained in memory. |
True
|
use_cache
|
bool
|
Forwarded to child model loading. |
True
|
seed_selection
|
Optional[str]
|
Optional seed selection for multi-seed child runs. |
None
|
gradiend_only
|
bool
|
If True, load only saved GRADIEND weights/mapping and skip the Hugging Face base model. Use this for weight-space comparisons that do not run model forwards. |
False
|
Source code in gradiend/trainer/suite/base.py
get_pair_definition
Return the pair definition for one child trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
child_id
|
str
|
Child trainer id. |
required |
get_trainer
Return one child trainer by id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
child_id
|
str
|
Child trainer id. |
required |
get_trainers
items
keys
plot_cross_encoding_heatmap
plot_cross_encoding_heatmap(*, label_mapping=None, pretty_groups=None, split='test', max_size=None, use_cache=True, metric='positive_mean', full_eval=True, encoder_eval='auto', allow_incomplete=False, seed_selection=None, seed_aggregate='mean', dispersion=None, normalize=False, order='input', cluster=False, row_label_mapping=None, column_label_mapping=None, **plot_kwargs)
Plot positive-pair cross-encoding heatmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_mapping
|
Optional[Dict[str, str]]
|
Optional child-id to display-label mapping. |
None
|
pretty_groups
|
Optional[Dict[str, List[str]]]
|
Optional display groups for rows/columns. |
None
|
split
|
str
|
Encoder split used when running evaluation. |
'test'
|
max_size
|
Optional[int]
|
Optional encoder-evaluation cap. |
None
|
use_cache
|
bool
|
Whether to use child evaluation/model caches. |
True
|
metric
|
str
|
Cross-encoding metric to plot. |
'positive_mean'
|
full_eval
|
bool
|
Whether child encoder evaluation includes all transitions. |
True
|
encoder_eval
|
str
|
Encoder evaluation policy: |
'auto'
|
allow_incomplete
|
bool
|
If True, tolerate missing child encoder results. |
False
|
seed_selection
|
Optional[str]
|
Optional seed selection for multi-seed children. |
None
|
seed_aggregate
|
str
|
Aggregate used for seed-level cross encoding. |
'mean'
|
dispersion
|
Optional[str]
|
Optional seed dispersion statistic. |
None
|
normalize
|
bool
|
If True, normalize rows by diagonal values. |
False
|
order
|
Any
|
Heatmap ordering strategy or explicit order. |
'input'
|
cluster
|
bool
|
If True, cluster heatmap rows/columns. |
False
|
row_label_mapping
|
Optional[Dict[str, str]]
|
Optional row display labels. |
None
|
column_label_mapping
|
Optional[Dict[str, str]]
|
Optional column display labels. |
None
|
**plot_kwargs
|
Any
|
Forwarded to comparison heatmap plotting. |
{}
|
Source code in gradiend/trainer/suite/base.py
plot_similarity_heatmap
Plot pairwise GRADIEND similarity heatmap for suite children.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_mapping
|
Optional[Dict[str, str]]
|
Optional child-id to display-label mapping. |
None
|
pretty_groups
|
Optional[Dict[str, List[str]]]
|
Optional display groups. |
None
|
use_cache
|
bool
|
Forwarded to child model loading. |
True
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Source code in gradiend/trainer/suite/base.py
plot_topk_overlap_heatmap
Plot top-k overlap heatmap for suite child GRADIEND models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label_mapping
|
Optional[Dict[str, str]]
|
Optional child-id to display-label mapping. |
None
|
pretty_groups
|
Optional[Dict[str, List[str]]]
|
Optional display groups. |
None
|
use_cache
|
bool
|
Forwarded to child model loading. |
True
|
**kwargs
|
Any
|
Forwarded to |
{}
|
Source code in gradiend/trainer/suite/base.py
train
Train every child trainer and return child_id -> result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments forwarded to child |
()
|
**kwargs
|
Any
|
Keyword arguments forwarded to child |
{}
|