MCPcopy Create free account
hub / github.com/Francis-Rings/FlashPortrait / convert_model_weight_to_float8

Function convert_model_weight_to_float8

wan/utils/fp8_optimization.py:19–34  ·  view source on GitHub ↗
(model, exclude_module_name=['embed_tokens'], device=None)

Source from the content-addressed store, hash-verified

17 replace_parameters_by_name(child_module, name_keywords, device)
18
19def convert_model_weight_to_float8(model, exclude_module_name=['embed_tokens'], device=None):
20 for name, module in model.named_modules():
21 flag = False
22 for _exclude_module_name in exclude_module_name:
23 if _exclude_module_name in name:
24 flag = True
25 if flag:
26 continue
27 for param_name, param in module.named_parameters():
28 flag = False
29 for _exclude_module_name in exclude_module_name:
30 if _exclude_module_name in param_name:
31 flag = True
32 if flag:
33 continue
34 param.data = param.data.to(torch.float8_e4m3fn)
35
36def autocast_model_forward(cls, origin_dtype, *inputs, **kwargs):
37 weight_dtype = cls.weight.dtype

Callers 2

fast_infer.pyFile · 0.90
infer.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected