transformer_lens.utilities.attribute_utils module¶
attribute_utils.
This module contains utility functions related to attributes
- transformer_lens.utilities.attribute_utils.get_nested_attr(obj, attr_str)¶
Retrieves a nested attribute from an object based on a dot-separated string.
For example, if attr_str is “a.b.c”, this function will return obj.a.b.c.
- Parameters:
obj (Any) – The object from which to retrieve the attribute.
attr_str (str) – A dot-separated string representing the attribute hierarchy.
- Returns:
The value of the nested attribute.
- Return type:
Any
- transformer_lens.utilities.attribute_utils.set_nested_attr(obj, attr_str, value)¶
Sets a nested attribute of an object based on a dot-separated string.
For example, if attr_str is “a.b.c”, this function will set the value of obj.a.b.c to value.
- Parameters:
obj (Any) – The object on which to set the attribute.
attr_str (str) – A dot-separated string representing the attribute hierarchy.
value (Any) – The value to set for the nested attribute.