Training¶
A generic teacher-training loop with checkpoint I/O.
polyweave.training ¶
Training utilities: a generic teacher-training loop and checkpoint I/O.
TeacherTrainResult
dataclass
¶
TeacherTrainResult(losses: List[float] = list(), pi_scales: List[float] = list(), exponent_abs_means: List[float] = list(), pi_shares: List[float] = list())
Outcome of :func:train_teacher.
load_checkpoint ¶
load_checkpoint(path: str, model: Module, optimizer: Optional[Optimizer] = None, map_location: Optional[Any] = None, strict: bool = True) -> Dict[str, Any]
Load weights into model (and optionally optimizer) from path.
Returns the stored meta dict (empty if none was saved).
Source code in polyweave/training/checkpoint.py
save_checkpoint ¶
save_checkpoint(path: str, model: Module, optimizer: Optional[Optimizer] = None, meta: Optional[Dict[str, Any]] = None) -> None
Save model (and optionally optimizer/meta) to path.
Parent directories are created if needed.
Source code in polyweave/training/checkpoint.py
train_teacher ¶
train_teacher(teacher: Module, students: Sequence[Module], *, sample_batch: SampleBatch, build_prototype: BuildPrototype, forward: Forward, steps: int, lr: float = 0.001, proto_noise_std: float = 0.0, grad_clip: Optional[float] = 1.0, cosine: bool = True, extra_params: Optional[Sequence[Parameter]] = None, log_every: int = 0, log_fn: Callable[[str], None] = print) -> TeacherTrainResult
Train teacher to generate weights for a population of students.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
teacher
|
Module
|
the hypernetwork teacher (must expose |
required |
students
|
Sequence[Module]
|
frozen students sampled uniformly each step. |
required |
sample_batch
|
SampleBatch
|
returns a fresh training batch. |
required |
build_prototype
|
BuildPrototype
|
maps |
required |
forward
|
Forward
|
maps |
required |
steps
|
int
|
number of optimisation steps. |
required |
lr
|
float
|
Adam learning rate. |
0.001
|
proto_noise_std
|
float
|
std of optional Gaussian noise added to the prototype (a regulariser; the paper's matched regime uses 0). |
0.0
|
grad_clip
|
Optional[float]
|
gradient-norm clip value (None to disable). |
1.0
|
cosine
|
bool
|
use cosine LR annealing over |
True
|
extra_params
|
Optional[Sequence[Parameter]]
|
additional parameters to optimise jointly with the teacher
(e.g. a :class: |
None
|
log_every
|
int
|
print a progress line every |
0
|
log_fn
|
Callable[[str], None]
|
sink for log lines (default |
print
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
TeacherTrainResult
|
class: |
Source code in polyweave/training/loop.py
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 | |