Skip to main content

OmegaConf plugin for Flytekit

Project description

Flytekit OmegaConf Plugin

Flytekit python natively supports serialization of many data types for exchanging information between tasks. The Flytekit OmegaConf Plugin extends these by the DictConfig type from the OmegaConf package as well as related types that are being used by the hydra package for configuration management.

Task example

from dataclasses import dataclass
import flytekitplugins.omegaconf  # noqa F401
from flytekit import task, workflow
from omegaconf import DictConfig

@dataclass
class MySimpleConf:
    _target_: str = "lightning_module.MyEncoderModule"
    learning_rate: float = 0.0001

@task
def my_task(cfg: DictConfig) -> None:
    print(f"Doing things with {cfg.learning_rate=}")


@workflow
def pipeline(cfg: DictConfig) -> None:
    my_task(cfg=cfg)


if __name__ == "__main__":
    from omegaconf import OmegaConf

    cfg = OmegaConf.structured(MySimpleConf)
    pipeline(cfg=cfg)

Transformer configuration

The transformer can be set to one of three modes:

Dataclass - This mode should be used with a StructuredConfig and will reconstruct the config from the matching dataclass during deserialisation in order to make typing information from the dataclass and continued validation thereof available. This requires the dataclass definition to be available via python import in the Flyte execution environment in which objects are (de-)serialised.

DictConfig - This mode will deserialize the config into a DictConfig object. In particular, dataclasses are translated into DictConfig objects and only primitive types are being checked. The definition of underlying dataclasses for structured configs is only required during the initial serialization for this mode.

Auto - This mode will try to deserialize according to the Dataclass mode and fall back to the DictConfig mode if the dataclass definition is not available. This is the default mode.

You can set the transformer mode globally or for the current context only the following ways:

from flytekitplugins.omegaconf import set_transformer_mode, set_local_transformer_mode, OmegaConfTransformerMode

# Set the global transformer mode using the new function
set_transformer_mode(OmegaConfTransformerMode.DictConfig)

# You can also the mode for the current context only
with set_local_transformer_mode(OmegaConfTransformerMode.Dataclass):
    # This will use the Dataclass mode
    pass
Since the DictConfig is flattened and keys transformed into dot notation, the keys of the DictConfig must not contain
dots.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flytekitplugins_omegaconf-1.16.21.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flytekitplugins_omegaconf-1.16.21-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file flytekitplugins_omegaconf-1.16.21.tar.gz.

File metadata

File hashes

Hashes for flytekitplugins_omegaconf-1.16.21.tar.gz
Algorithm Hash digest
SHA256 922880b19b77efaf47bcc686728638e61d697a72e1c6dc51edece6e343cf9eeb
MD5 c902095967384e2fb54018c83f7a1c51
BLAKE2b-256 1f1ae1b246134698d93bab2baf1bb8b041b24f7e91ebd32ea3a07e196dd0fabd

See more details on using hashes here.

File details

Details for the file flytekitplugins_omegaconf-1.16.21-py3-none-any.whl.

File metadata

File hashes

Hashes for flytekitplugins_omegaconf-1.16.21-py3-none-any.whl
Algorithm Hash digest
SHA256 3bc2083d29b10e28a207c21ad86abaca78a73f7afb8cd8fd5921d19ed1ece3ac
MD5 fbcacb48eb5029c232d14cb606256e85
BLAKE2b-256 b3276882cc77325a1bce4d0f55eee8fdebf7642ede14f3a805bff42b723d4adc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page