MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / recursive_setattr

Function recursive_setattr

deepspeed/utils/module_utils.py:23–38  ·  view source on GitHub ↗

Recursively set the attribute of a module. Args: model (`torch.nn.Module`) The model to set the attribute in. module_name (`str`) The name of the module to set the attribute in. module (`torch.nn.Module`) The module to set the attr

(model, module_name, module)

Source from the content-addressed store, hash-verified

21
22
23def recursive_setattr(model, module_name, module):
24 """
25 Recursively set the attribute of a module.
26 Args:
27 model (`torch.nn.Module`)
28 The model to set the attribute in.
29 module_name (`str`)
30 The name of the module to set the attribute in.
31 module (`torch.nn.Module`)
32 The module to set the attribute to.
33 """
34 split_list = module_name.split('.')
35 output = model
36 for name in split_list[:-1]:
37 output = getattr(output, name)
38 output.__setattr__(split_list[-1], module)

Callers 2

convert_to_random_ltdFunction · 0.90

Calls 1

__setattr__Method · 0.45

Tested by 1