nemo_automodel.utils.yaml_utils
#
Module Contents#
Functions#
Context manager for safely adding and removing custom YAML representers. |
|
Represent functions in YAML. |
|
Represent torch dtypes in YAML. |
|
General object representer for YAML. |
|
Represent functools.partial objects in YAML. |
|
Represent enums in YAML. |
|
Represent transformers GenerationConfig objects in YAML. |
API#
- nemo_automodel.utils.yaml_utils.safe_yaml_representers() collections.abc.Generator[None, None, None] [source]#
Context manager for safely adding and removing custom YAML representers.
Temporarily adds custom representers for functions, classes, and other objects to the YAML SafeDumper, and restores the original representers when exiting the context.
Usage: with safe_yaml_representers(): yaml_str = yaml.safe_dump(my_complex_object)
- nemo_automodel.utils.yaml_utils._function_representer(dumper, data)[source]#
Represent functions in YAML.
- nemo_automodel.utils.yaml_utils._torch_dtype_representer(dumper, data)[source]#
Represent torch dtypes in YAML.
- nemo_automodel.utils.yaml_utils._safe_object_representer(dumper, data)[source]#
General object representer for YAML.
This function is a fallback for objects that donβt have specific representers. If the object has qualname attr, the target is set to fβ{inspect.getmodule(obj).name}.{obj.qualname}β. If the object does not have a qualname attr, the target is set from its class attr. The call key is used to indicate whether the target should be called to create an instance.
- Parameters:
dumper (yaml.Dumper) β The YAML dumper to use for serialization.
data (Any) β The data to serialize.
- Returns:
The YAML representation of the data.