#1024·mamba

Mamba3 的 step() 方法是非确定性的,不符合 forward() 方法

作者: H-E3创建于 2026年8月26日更新于 2026年9月17日

□问.

我注意到,在 " step() " 和 " Forward() " 之间有产出差异。

当使用相同的模型并在完全相同的输入序列中进行喂入时,直接引用"Mamba3.forward()"与运行多个"Mamba3.step()"在循环中调用输出,结果明显不同,最大相差值接近一.

更重要的是,** 运行相同的`步骤()'循环多次将返回不一致的结果**,即使不修改投入或参数。

相比之下,对Mamba2实施的相应测试案例表现可靠;其最大的绝对差异在`5e'5左右。

我想知道是什么引发了这种不一致。 我也想知道这只虫子 是否源于我运行时环境中的问题

□再现.

我的测试代码如下:

zz
导入火炬
从mamba ssm导入mamba3,mamba2

火炬. manual 种子( 0)
dtype=火炬.float32
m1 = (单位:千美元)
Mamba3(d model=64, d state=64, headdim=16, 块 大小=16, is mimo=法尔斯, dtype=dtype) 互联网档案馆的存檔,存档日期2011-12-21.
.cuda () (中文(简体) ).
.eval () (中文(简体) ).
(中文(简体) ).
m2 = (单位:千美元)
Mamba2(d model=64,d state=64,头dim=16,块 大小=16,dtype=d类型)
.cuda () (中文(简体) ).
.eval () (中文(简体) ).
(中文(简体) ).

批号,下表,d 型号=1、10、64
下行=火炬.randn (批,下行,d model,dtype=dtype.cuda ()# [B,L,D]

使用火炬.no grad():
# -- - - - - - - - - 1型号
前出站 1 = m1(seq)# [B,L,D]
角度   dt 状态, ssm 状态, k  state, v  state = m1. assocate  inference cache()
批量 大小=批量, 最大  Seqlen=无, dtype=dtype, 设备=seq.device
# 分配缓存用于流出推断
step 1 = 火炬. freety(seqlen, slot, d model, dtype=dtype). cuda () # [L, B, D] (中文(简体) ).
在范围(seqlen)中的 t : # 模拟流推论, 一步一步地
# step () u/出:(批, d model)
u=后[:,t,]#[B,D]
# 打印 (u. shape) (英语).
step out, 角度  dt  state, ssm  state, k  state, v  state = m1. step ()
u, 角度   dt  state, ssm  state, k  state, v  state
(中文(简体) ).
步入 1[t] = 步出

# -- - - - - - - - 型号2
前置 出 2 = m2(seq) # [B,L,D]
conv state, ssm state = m2. asslocate  inference cache () 缩写:
批量 大小=批量, 最大  Seqlen=无, dtype=dtype, 设备=seq.device
(中文(简体) ).
step 2 = 火炬.dempty (seqlen, slot, d model, dtype=dtype). cuda () # [L, B, D] (中文(简体) ).
t 在范围(seqlen)中:
# step( ) u/出:(批次, 1, d  model)
u=后[:,t,]#[B,D]
u=u.unsqueeze(1)# [B, 1, D] (中文(简体) ).
# 打印 (u. shape) (英语).
步出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站出站
u, conv 状态, ssm 状态
(中文(简体) ).
step 2[t] = step out.squeeze(1) # [B, D] (中文(简体) ).

# [L,B,D] -- > [B,L,D]
流出 1 = 步入 1. Transpose (0, 1)
流出 2 = 步入 2. transpose (0, 1)

diff 1=(向前 出 1-流出 1). abs ()
diff 2=(向前 出 2-流 2)abs()
print( f"Mamba3 step vs forward: max|diff|={diff  1. max (: 2.e}").
print( f"Mamba2 step vs forward: max|diff|={diff  2. max (: 2.e}")

我觉得 . . . . . . .

内容来源: state-spaces/mamba