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
Built Distribution
File details
Details for the file flytekitplugins_omegaconf-1.13.8.tar.gz
.
File metadata
- Download URL: flytekitplugins_omegaconf-1.13.8.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1aec917988bfa788729c7f91d6b6b7e863c80ff6b9c8598c659743d67b90de0 |
|
MD5 | 2a8a4119d116f79d1659c186ad79974e |
|
BLAKE2b-256 | 3ee105e8ea3125fa88d08532079c9fc596f85b718cc7e7a1e83fe6973cb7483f |
File details
Details for the file flytekitplugins_omegaconf-1.13.8-py3-none-any.whl
.
File metadata
- Download URL: flytekitplugins_omegaconf-1.13.8-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1eaba688bd74bb1ab6adbbce55e28bb137ecf19275234fa104d528e1192f5be6 |
|
MD5 | b7283383b6745e99cc6a1e07260dbaf7 |
|
BLAKE2b-256 | a346ca8b21f74885914b654a3c0c943fa98bc747cffa484f8a9bfd5a32004861 |