mstar.model.glm5_next.mhc#

GLM-5.3-Flash mHC: manifold-constrained hyper-connections.

Functions

expand_streams(hidden_states[, hc_mult])

Model entry: replicate embeddings [B, S, D] into [B, S, hc_mult, D].

sinkhorn_normalize(matrix[, num_iters, eps])

Project a positive [..., H, H] matrix onto the doubly-stochastic manifold.

update_streams(residual, sublayer_out, post, ...)

Write a sublayer output back into the streams: place by post, mix by comb.

Classes

Glm5NextHyperConnection(hidden_size[, ...])

One mHC site: learned collapse/placement/mixing weights from the live streams.

Glm5NextHyperHead(*args, **kwargs)

Model exit: collapse streams [B, S, H, D] -> [B, S, D].

UnweightedRMSNorm([eps])

RMSNorm with no learned weight, over the last (flattened 4*hidden) axis.

class mstar.model.glm5_next.mhc.Glm5NextHyperConnection(hidden_size, hc_mult=GLM5_NEXT_HC_MULT, hc_eps=GLM5_NEXT_HC_EPS, hc_sinkhorn_iters=GLM5_NEXT_HC_SINKHORN_ITERS, rms_norm_eps=GLM5_NEXT_RMS_NORM_EPS)[source]#

Bases: Module

One mHC site: learned collapse/placement/mixing weights from the live streams.

Parameters:
finalize_weights()[source]#

Cache the fp32 fn; call after the weights are loaded.

Return type:

None

forward(hidden_streams)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

hidden_streams (Tensor)

Return type:

tuple[Tensor, Tensor, Tensor]

forward_fused(hidden_streams, norm, update=None)[source]#

forward + norm (+ the previous update_streams) in two kernels; see fused_decode.hc_pre.

process_weights_after_loading(device)[source]#
Return type:

None

reset_parameters()[source]#

HF _init_weights for this module; checkpoint load overwrites.

Return type:

None

class mstar.model.glm5_next.mhc.Glm5NextHyperHead(*args, **kwargs)[source]#

Bases: Module

Model exit: collapse streams [B, S, H, D] -> [B, S, D].

Parameters:
forward(hidden_streams)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

hidden_streams (Tensor)

Return type:

Tensor

class mstar.model.glm5_next.mhc.UnweightedRMSNorm(eps=GLM5_NEXT_RMS_NORM_EPS)[source]#

Bases: Module

RMSNorm with no learned weight, over the last (flattened 4*hidden) axis.

Parameters:

eps (float)

forward(x)[source]#

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

mstar.model.glm5_next.mhc.expand_streams(hidden_states, hc_mult=GLM5_NEXT_HC_MULT)[source]#

Model entry: replicate embeddings [B, S, D] into [B, S, hc_mult, D].

Parameters:
Return type:

Tensor

mstar.model.glm5_next.mhc.sinkhorn_normalize(matrix, num_iters=GLM5_NEXT_HC_SINKHORN_ITERS, eps=GLM5_NEXT_HC_EPS)[source]#

Project a positive [..., H, H] matrix onto the doubly-stochastic manifold.

Parameters:
Return type:

Tensor

mstar.model.glm5_next.mhc.update_streams(residual, sublayer_out, post, comb)[source]#

Write a sublayer output back into the streams: place by post, mix by comb.

Parameters:
Return type:

Tensor