MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / replace_layer

Method replace_layer

diffsynth/models/flux_dit.py:532–549  ·  view source on GitHub ↗
(model)

Source from the content-addressed store, hash-verified

530 return hidden_states
531
532 def replace_layer(model):
533 for name, module in model.named_children():
534 if isinstance(module, torch.nn.Linear):
535 with init_weights_on_device():
536 new_layer = quantized_layer.Linear(module.in_features,module.out_features)
537 new_layer.weight = module.weight
538 if module.bias is not None:
539 new_layer.bias = module.bias
540 # del module
541 setattr(model, name, new_layer)
542 elif isinstance(module, RMSNorm):
543 if hasattr(module,"quantized"):
544 continue
545 module.quantized= True
546 new_layer = quantized_layer.RMSNorm(module)
547 setattr(model, name, new_layer)
548 else:
549 replace_layer(module)
550
551 replace_layer(self)
552

Callers

nothing calls this directly

Calls 1

init_weights_on_deviceFunction · 0.85

Tested by

no test coverage detected