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

Function recursive_setattr

deepspeed/inference/quantization/utils.py:172–187  ·  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

170
171
172def recursive_setattr(model, module_name, module):
173 """
174 Recursively set the attribute of a module.
175 Args:
176 model (`torch.nn.Module`)
177 The model to set the attribute in.
178 module_name (`str`)
179 The name of the module to set the attribute in.
180 module (`torch.nn.Module`)
181 The module to set the attribute to.
182 """
183 split_list = module_name.split('.')
184 output = model
185 for name in split_list[:-1]:
186 output = getattr(output, name)
187 output.__setattr__(split_list[-1], module)
188
189
190def concat_to_compat_param(quantized_weight: Tensor,

Callers 1

Calls 1

__setattr__Method · 0.45

Tested by

no test coverage detected