@@ -404,19 +404,51 @@ def get_lm_head_weights(model: nn.Module) -> torch.Tensor:
404404
405405
406406def get_attr_by_name (obj , name ):
407+ """Get an attribute specified by a dot-separated path on an object.
408+
409+ Args:
410+ obj: The root object from which to resolve the attribute path.
411+ name (str): Dot-separated attribute path (e.g., "a.b.c").
412+
413+ Returns:
414+ The value of the resolved attribute.
415+
416+ Raises:
417+ AttributeError: If any component in the path does not exist.
418+ """
407419 for part in name .split ("." ):
408420 obj = getattr (obj , part )
409421 return obj
410422
411423
412424def set_attr_by_name (obj , name , value ):
425+ """Set an attribute specified by a dot-separated path on an object.
426+
427+ Args:
428+ obj: The root object on which to set the attribute.
429+ name (str): Dot-separated attribute path (e.g., "a.b.c").
430+ value: The value to assign to the target attribute.
431+
432+ Raises:
433+ AttributeError: If any intermediate component in the path does not exist.
434+ """
413435 parts = name .split ("." )
414436 for part in parts [:- 1 ]:
415437 obj = getattr (obj , part )
416438 setattr (obj , parts [- 1 ], value )
417439
418440
419441def del_attr_by_name (obj , name ):
442+ """Delete an attribute specified by a dot-separated path from an object.
443+
444+ Args:
445+ obj: The root object from which to delete the attribute.
446+ name (str): Dot-separated attribute path (e.g., "a.b.c").
447+
448+ Raises:
449+ AttributeError: If any intermediate component in the path does not exist
450+ or if the final attribute does not exist.
451+ """
420452 parts = name .split ("." )
421453 for part in parts [:- 1 ]:
422454 obj = getattr (obj , part )
0 commit comments