[BUG] GraniteMoeHybrid 在调用 ssm_update 时会丢失缓存长度。
import mlx.core as mx import mlx_lm from mlx_lm.generate import BatchGenerator, generate_step from mlx_lm.models import cache as cache_mod, granitemoehybrid as G from mlx_lm.models.ssm import ssm_update mx.random.seed(0) model = G.Model(G.ModelArgs( model_type="granitemoehybrid", vocab_size=100, hidden_size=64, intermediate_size=128, shared_intermediate_size=128, num_hidden_layers=2, layer_types=["mamba", "attention"], max_position_embeddings=512, num_attention_heads=4, num_key_value_heads=2, attention_bias=False, embedding_multiplier=1.0, attention_multiplier=0.25, logits_scaling=1.0, residual_multiplier=1.0, rms_norm_eps=1e-5, rope_theta=10000.0, position_embedding_type="nope", mamba_n_heads=4, mamba_d_head=32, mamba_d_state=32, mamba_d_conv=4, mamba_n_groups=1, mamba_proj_bias=False, mamba_conv_bias=True)) for layer in model.layers: # random init gives the recurrent state almost no weight; make it matter, if hasattr(layer, "mamba"): # as it does in a trained checkpoint (slow decay, larger conv output) layer.mamba.A_log = mx.full(layer.mamba.A_log.shape, -4.0) layer.mamba.conv1d.weight = layer.mamba.conv1d.weight * 30 mx.eval(model.parameters()) long_prompt, short_prompt = list(range(1, 13)), [7, 8, 9]
def
内容来源: ml-explore/mlx-lm