config

class olmo_core.config.Config[source]

Bases: object

A base class for configuration dataclasses.

Important

When you subclass this you should still decorate your subclasses with @dataclass. For example:

@dataclass
class MyConfig(Config):
    ...

Important

Config classes need to be serializable, so you should only use simple types for your fields. Though you can use nested configs.

CLASS_NAME_FIELD = '_CLASS_'

The name of the class name field inject into the dictionary from as_dict() or as_config_dict().

as_dict(*, exclude_none=False, exclude_private_fields=False, exclude=None, include_class_name=False, include_registered_name=False, json_safe=False, recurse=True)[source]

Convert into a regular Python dictionary.

Parameters:
  • exclude_none (bool, default: False) – Don’t include values that are None.

  • exclude_private_fields (bool, default: False) – Don’t include private fields.

  • exclude (Optional[Collection[str]], default: None) – A list of field names to exclude.

  • include_class_name (bool, default: False) – Include a field for the name of the class.

  • include_registered_name (bool, default: False) – If the config is Registrable, include the registered name under the key “type”.

  • json_safe (bool, default: False) – Output only JSON-safe types.

  • recurse (bool, default: True) – Recurse into fields that are also configs/dataclasses.

Return type:

Dict[str, Any]

as_config_dict()[source]

A convenience wrapper around as_dict() for creating JSON-safe dictionaries suitable for recording the config.

Return type:

Dict[str, Any]

apply(func)[source]

Recursively apply a function to every config instance field, including self.

Parameters:

func (Callable[[Config], None]) – The function to apply.

validate()[source]

Validate fields in self. This may modify self in-place.

merge(dotlist, prefix=None, strict=True)[source]

Merge self with fields from a “dotlist”, creating a new object.

Parameters:
  • dotlist (List[str]) – A list of field attributes with dot notation, e.g. foo.bar=1.

  • prefix (Optional[str], default: None) – Only use override items in the dotlist that start with a given prefix name, and strip that prefix (including the subsequent “.”) before applying the overrides.

  • strict (bool, default: True) – Parse the dotlist strictly.

Return type:

Self

replace(**changes)[source]

Creates a new object of the same type, replacing fields with values from changes.

Return type:

Self

copy(deep=True)[source]

Creates a new object of the same type, with the same values.

Return type:

Self

classmethod from_dict(data, overrides=None)[source]

Initialize from a regular Python dictionary.

Parameters:
  • data (Dict[str, Any]) – A Python dictionary.

  • overrides (Optional[List[str]], default: None) – A list of field overrides with dot notation, e.g. foo.bar=1.

Return type:

TypeVar(C, bound= Config)

class olmo_core.config.DType(value)[source]

Bases: StrEnum

An enumeration of supported PyTorch data types.

class olmo_core.config.StrEnum(value)[source]

Bases: str, Enum

This is equivalent to Python’s enum.StrEnum since version 3.11. We include this here for compatibility with older version of Python.

class olmo_core.config.Registrable(*, type=None)[source]

Bases: object