Students¶
The networks whose weights a teacher generates (CNN, transformer, and Sigma-Pi variants).
polyweave.students ¶
Student networks whose weights a hypernetwork teacher generates.
Two families, mirroring the paper's experiments:
- :class:
CNNStudent— a small CIFAR-style convolutional classifier with its first conv layer (conv1/bn1/pool1) factored out so a teacher can replace just those weights (Experiment 2), while still allowing a generated linear head (Experiment 1). Three concrete architectures (A/B/C) provide the cross-architecture seen/unseen split. - :class:
TinyTransformerStudent— an attention-only transformer for the synthetic relational-lookup task whose per-layer Q/K projections a teacher generates (Experiment 3).
CNNStudent ¶
CNNStudent(trunk_rest: Module, feature_dim: int = 256, num_classes: int = 10, in_ch: int = 3, conv1_out: int = 32, kernel_size: int = 3)
Bases: Module
A convolutional classifier with a replaceable first conv layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trunk_rest
|
Module
|
the body of the network mapping the pooled |
required |
feature_dim
|
int
|
width of the penultimate feature vector. |
256
|
num_classes
|
int
|
number of output classes. |
10
|
in_ch
|
int
|
input image channels (3 for CIFAR). |
3
|
conv1_out
|
int
|
output channels of |
32
|
kernel_size
|
int
|
|
3
|
Source code in polyweave/students/cnn.py
SigmaPiStudent ¶
SigmaPiStudent(width: int = 32, num_classes: int = 10, in_ch: int = 3, kernel_size: int = 3, img_size: int = 32)
Bases: Module
A classifier with a generated multiplicative (Sigma-Pi) target block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
channel width of the stem output and the Sigma-Pi block (the block is channels-preserving, so this is the generated target width). |
32
|
num_classes
|
int
|
number of output classes. |
10
|
in_ch
|
int
|
input image channels (3 for CIFAR-like data). |
3
|
kernel_size
|
int
|
kernel size of both the stem and the Sigma-Pi block. |
3
|
img_size
|
int
|
spatial size of the (square) input, used to size the head. |
32
|
Source code in polyweave/students/sigmapi.py
pi_scale_mean ¶
TinyTransformerStudent ¶
TinyTransformerStudent(vocab_size: int = 64, seq_len: int = 10, num_classes: int = 5, d_model: int = 64, n_heads: int = 4, n_layers: int = 2, activation: str = 'relu', emb_seed: int = 7, dropout: float = 0.0)
Bases: Module
Attention-only transformer with shared frozen embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vocab_size
|
int
|
token vocabulary size. |
64
|
seq_len
|
int
|
sequence length (query token is at the last position). |
10
|
num_classes
|
int
|
number of key slots / output classes. |
5
|
d_model
|
int
|
model width (uniform across students so the generated Q/K target is fixed-size). |
64
|
n_heads
|
int
|
number of attention heads. |
4
|
n_layers
|
int
|
number of transformer blocks. |
2
|
activation
|
str
|
per-architecture pointwise activation in each block. |
'relu'
|
emb_seed
|
int
|
seed for the shared, frozen token/positional embeddings. |
7
|
dropout
|
float
|
attention dropout (default 0). |
0.0
|
Source code in polyweave/students/transformer.py
make_cnn_student ¶
make_cnn_student(arch: str = 'A', *, feature_dim: int = 256, num_classes: int = 10, in_ch: int = 3, conv1_out: int = 32, kernel_size: int = 3) -> CNNStudent
Build one CNN student of architecture arch in {"A", "B", "C"}.
The trunks differ in width/depth but all consume the same fixed conv1
output (assuming a 32x32 input that has been pooled to 16x16 then reduced to
4x4 by the trunk's two pooling stages).
Source code in polyweave/students/cnn.py
make_cnn_students ¶
Build one student per architecture name (defaults to A, B, C).
Source code in polyweave/students/cnn.py
freeze_except_qk ¶
Freeze everything except every block's packed in_proj (Q/K/V).
Source code in polyweave/students/transformer.py
mask_qk_grads ¶
Zero the V slice of every block's packed projection gradient.
Lets an optimiser step the Q/K rows while leaving the (frozen) value projection untouched, even though Q/K/V share one packed parameter.
Source code in polyweave/students/transformer.py
reinit_qk ¶
Xavier-reinitialise the Q and K slices of every block (V left as-is).