MCPcopy Create free account
hub / github.com/lingeringlight/START / dt_init

Method dt_init

models/vmamba.py:340–365  ·  view source on GitHub ↗
(dt_rank, d_inner, dt_scale=1.0, dt_init="random", dt_min=0.001, dt_max=0.1, dt_init_floor=1e-4,
                **factory_kwargs)

Source from the content-addressed store, hash-verified

338
339 @staticmethod
340 def dt_init(dt_rank, d_inner, dt_scale=1.0, dt_init="random", dt_min=0.001, dt_max=0.1, dt_init_floor=1e-4,
341 **factory_kwargs):
342 dt_proj = nn.Linear(dt_rank, d_inner, bias=True, **factory_kwargs)
343
344 # Initialize special dt projection to preserve variance at initialization
345 dt_init_std = dt_rank ** -0.5 * dt_scale
346 if dt_init == "constant":
347 nn.init.constant_(dt_proj.weight, dt_init_std)
348 elif dt_init == "random":
349 nn.init.uniform_(dt_proj.weight, -dt_init_std, dt_init_std)
350 else:
351 raise NotImplementedError
352
353 # Initialize dt bias so that F.softplus(dt_bias) is between dt_min and dt_max
354 dt = torch.exp(
355 torch.rand(d_inner, **factory_kwargs) * (math.log(dt_max) - math.log(dt_min))
356 + math.log(dt_min)
357 ).clamp(min=dt_init_floor)
358 # Inverse of softplus: https://github.com/pytorch/pytorch/issues/72759
359 inv_dt = dt + torch.log(-torch.expm1(-dt))
360 with torch.no_grad():
361 dt_proj.bias.copy_(inv_dt)
362 # Our initialization would set all Linear.bias to zero, need to mark this one as _no_reinit
363 dt_proj.bias._no_reinit = True
364
365 return dt_proj
366
367 @staticmethod
368 def A_log_init(d_state, d_inner, copies=1, device=None, merge=True):

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected