Nizar Hattab
04/18/2024, 9:38 AMfrom pydantic import BaseModel
class CustomInput(BaseModel):
field1: ...
field2: ...
@task
def do_something(config: CustomInput):
....
previously, I used dataclass instead of pydantic BaseModel and on the UI it accepted json object as input. However, now with BaseModel, a warning shows up on registration/running saying that this type is not supported by default and will default to a pythonPickle.. and on the UI it only accepts a pickle file now .
Unsupported Type <class 'CustomInput'> found, Flyte will default to use PickleFile as the transport. Pickle can only be used to send objects between the exact same version of Python, and we strongly recommend to use python type that flyte support.
Later on, If a pickle file is passed, it doesn't get converted to CustomInput object.
I installed pydantic plugin
flytekit 1.11.0
flytekitplugins-pydantic 1.11.0
pydantic 2.7.0
Am I doing something wrong or is this the expected behaviour?Grantham Taylor
04/18/2024, 11:42 AM@pydantic.dataclasses.dataclass
and inherit from DataClassJSONMixin
Grantham Taylor
04/18/2024, 11:43 AMNizar Hattab
04/18/2024, 11:43 AMGrantham Taylor
04/18/2024, 11:54 AM@cached_property
. My understanding to the difference is that the property of a computed field is cached between multiple components, whereas a @cached_property is only cached within each individual component. So, effectively, you would need to re-compute the property for each new task.Grantham Taylor
04/18/2024, 11:59 AMNizar Hattab
04/18/2024, 11:59 AMGrantham Taylor
04/18/2024, 12:26 PM@computed_field
and it (de)serializes as expected.
from typing import Annotated
import pydantic
from mashumaro.mixins.json import DataClassJSONMixin
@pydantic.dataclasses.dataclass
class Hyperparameters(DataClassJSONMixin):
batch_size: Annotated[int, pydantic.Field(gt=0, le=2048)] = 128
n_context: Annotated[int, pydantic.Field(gt=0, le=2048)] = 128
d_hidden: Annotated[int, pydantic.Field(gt=1, le=256)] = 64
@pydantic.computed_field
def memory_complexity(self) -> int:
return self.n_context * self.n_context * self.d_hidden + self.n_context * self.d_hidden * self.d_hidden