Tensor roles¶
A role is a label on a tensor: weight, adam_m, adam_v, adam_vmax, momentum, muon_momentum, step, or other. It is not part of the tensor's bytes. A state schema sets it from the tensor's path in the saved state, and an assigner can read it to pick a codec.
Why a tensor has a role¶
A role lets a codec or an analysis treat first moments, second moments, and weights differently. An assigner reads the role of each tensor to pick its codec, so the weights can keep one codec while a moment uses another (see Choose codecs per role). jabara bench and jabara.bench.compare report one row per candidate and role.
Why the role is a label, not data¶
The role is not in the bytes, so it plays no part in matching a tensor to its base. A delta archive reads back against a base tensor with the same name, dtype, and shape, whatever role either carries. A new optimizer needs a new schema, not a new archive format (see Add a codec, an assigner, a state schema, or a file format).
Where the roles come from¶
OptimizerSchema sets the role from the last element of a tensor's path: exp_avg is adam_m, exp_avg_sq is adam_v, max_exp_avg_sq is adam_vmax, momentum_buffer is momentum, step is step, and anything else is other. MuonSchema gives momentum_buffer the role muon_momentum. WeightsSchema gives every tensor weight, and every tensor of a safetensors file is a weight.
The default schema of save_state is OptimizerSchema, so the tensors of a model's state_dict get the role other unless you pass WeightsSchema (see Save and load state in a plain PyTorch loop).