Metrics Hooks
trainer_tools.hooks.metrics.MetricsHook
Bases: MainProcessHook
Aggregates data from multiple Metrics and logs to console/tracker. Only ONE instance of this hook is needed per Trainer.
Source code in trainer_tools/hooks/metrics/metrics_hook.py
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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
__init__(metrics, verbose=True, tracker_type=None, config=None, freq=1, log_file='metrics.jsonl', name=None, project=None, **tracker_kwargs)
Aggregates Metric outputs and logs them to the console and/or a tracker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
List[Metric]
|
List of :class: |
required |
verbose
|
bool
|
If |
True
|
tracker_type
|
Optional[str]
|
Backend to use for logging. Supported values are
|
None
|
config
|
Union[dict, str, None]
|
Hyperparameter config forwarded to the tracker on init.
Accepts a |
None
|
freq
|
int
|
Step interval at which step-level metrics are logged. |
1
|
log_file
|
Optional[str]
|
Path to the JSONL file used when |
'metrics.jsonl'
|
name
|
Optional[str]
|
Run name forwarded to the tracker. Convenience alias for
passing |
None
|
project
|
Optional[str]
|
Project name forwarded to the tracker. Convenience alias
for passing |
None
|
**tracker_kwargs
|
Any
|
Additional keyword arguments passed to the
tracker's |
{}
|
Source code in trainer_tools/hooks/metrics/metrics_hook.py
Included Metrics
Base Metric Class
trainer_tools.hooks.Metric
Bases: ABC
Base class for data collection strategies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Identifier for the metric. |
None
|
freq
|
int
|
How often to collect (in steps) during TRAINING. Validation always collects every step. |
1
|
phase
|
str
|
The hook method name where collection occurs (e.g. 'after_loss'). |
'after_step'
|
use_prefix
|
bool
|
If True (default), keys are prefixed with 'train_'/'valid_'. If False, keys are logged exactly as returned (e.g. 'grad_norm'). |
True
|
Source code in trainer_tools/hooks/metrics/base.py
__init__(name=None, freq=1, phase='after_step', use_prefix=True)
__call__(trainer)
abstractmethod
should_run(trainer)
get_value(trainer, key, fn=None)
Helper to extract a value from trainer.result or compute it via fn.
Source code in trainer_tools/hooks/metrics/base.py
Loss Metric
trainer_tools.hooks.Loss
Bases: Metric
Source code in trainer_tools/hooks/metrics/base.py
Accuracy Metric
trainer_tools.hooks.Accuracy
Bases: Metric