@@ -246,6 +246,19 @@ def forward(
246246 return temb , temb_proj , encoder_hidden_states , encoder_hidden_states_image
247247
248248
249+ def _default_vsa_gate (linear : Linear , bias_value : float ) -> None :
250+ """Default a VSA gate Linear absent from the checkpoint: weight=0, bias=bias_value
251+ (G_c=0 / G_f=1, preserving dense behavior at sparsity=0)."""
252+ if not linear ._weights_created :
253+ linear .create_weights ()
254+ if linear .weight .is_meta :
255+ return
256+ with torch .no_grad ():
257+ linear .weight .zero_ ()
258+ if linear .bias is not None :
259+ linear .bias .fill_ (bias_value )
260+
261+
249262class WanBlock (nn .Module ):
250263 def __init__ (
251264 self ,
@@ -417,32 +430,6 @@ def __init__(
417430 torch .empty (1 , 6 , hidden_size ).normal_ (std = hidden_size ** - 0.5 )
418431 )
419432
420- def init_gate_compress_zero (self ) -> None :
421- """Zero-initialize to_gate_compress."""
422- if self .to_gate_compress is None :
423- return
424- if not self .to_gate_compress ._weights_created :
425- self .to_gate_compress .create_weights ()
426- if self .to_gate_compress .weight .is_meta :
427- return
428- with torch .no_grad ():
429- self .to_gate_compress .weight .zero_ ()
430- if self .to_gate_compress .bias is not None :
431- self .to_gate_compress .bias .zero_ ()
432-
433- def init_gate_fine_default (self ) -> None :
434- """Initialize to_gate_fine to emit constant 1 (weight=0, bias=1)."""
435- if self .to_gate_fine is None :
436- return
437- if not self .to_gate_fine ._weights_created :
438- self .to_gate_fine .create_weights ()
439- if self .to_gate_fine .weight .is_meta :
440- return
441- with torch .no_grad ():
442- self .to_gate_fine .weight .zero_ ()
443- if self .to_gate_fine .bias is not None :
444- self .to_gate_fine .bias .fill_ (1.0 )
445-
446433 def forward (
447434 self ,
448435 x ,
@@ -839,7 +826,6 @@ def load_weights(self, weights: dict) -> None:
839826 }
840827 loader = DynamicLinearWeightLoader (self .model_config , params_map = params_map )
841828
842- loaded_linears : set = set ()
843829 for name , module in tqdm (self .named_modules (), desc = "Loading weights" ):
844830 if len (module ._parameters ) == 0 :
845831 continue
@@ -849,7 +835,12 @@ def load_weights(self, weights: dict) -> None:
849835
850836 if weight_dicts :
851837 loader .load_linear_weights (module , name , weight_dicts )
852- loaded_linears .add (name )
838+ # VSA gates absent from the checkpoint default to G_c=0 / G_f=1
839+ # (dense behavior at sparsity=0).
840+ elif name .endswith (".to_gate_compress" ):
841+ _default_vsa_gate (module , 0.0 )
842+ elif name .endswith (".to_gate_fine" ):
843+ _default_vsa_gate (module , 1.0 )
853844 elif "add_k_proj" in name or "add_v_proj" in name :
854845 logger .info (f"[Weight Loading] No weights found for I2V module: { name } " )
855846 elif isinstance (module , RMSNormTPAware ):
@@ -863,20 +854,6 @@ def load_weights(self, weights: dict) -> None:
863854 module_weights [param_name ].to (self .model_config .torch_dtype )
864855 )
865856
866- # Default any VSA gates not loaded from the checkpoint: G_c=0, G_f=1
867- # (preserves dense behavior at sparsity=0).
868- for name , module in self .named_modules ():
869- if not isinstance (module , WanBlock ):
870- continue
871- if module .to_gate_compress is not None :
872- gate_path = f"{ name } .to_gate_compress" if name else "to_gate_compress"
873- if gate_path not in loaded_linears :
874- module .init_gate_compress_zero ()
875- if module .to_gate_fine is not None :
876- gate_path = f"{ name } .to_gate_fine" if name else "to_gate_fine"
877- if gate_path not in loaded_linears :
878- module .init_gate_fine_default ()
879-
880857 def post_load_weights (self ) -> None :
881858 """Call post_load_weights on all Linear modules and convert embedders to target dtype."""
882859 # Convert condition_embedder components to target dtype
0 commit comments