Closed freider closed 2 months ago
One thing I don't fully understand — what's "strict" about the params here? That they need to have type annotations in the modal class constructor?
Strict as in strictly typed in some sense, and that they (for now) only allow int
and str
types.
A somewhat unintended (positive) side effect of this mode is that it enforces the right arguments and types are supplied already at the call site, avoiding launch of containers with invalid params.
The old "mode" just happily let you instantiate the class with whatever *args, **kwargs
you wanted and it wouldn't actually explode until your already newly launched container tried to supply those to the underlying class.
A somewhat unintended (positive) side effect of this mode is that it enforces the right arguments and types are supplied already at the call site, avoiding launch of containers with invalid params.
Yeah that's a plus!
Alternative implementation of #1968 using a simple proto schema instead of cbor2 to encode the parameters.
As long as we are confident the encoded payload will be deterministic, this would be a pretty clean solution IMO as it enforces types harder in the serialization layer than cbor2.
Updated PR description from #1968
In "strict" parameter mode, class parameterization change behavior in the following ways:
serialized_params
use the new proto serialization formatclass_parameter_format=PARAM_SERIALIZATION_FORMAT_PROTO
on theFunction
definition to indicate the serialization protocol to be usedclass_parameter_schema
(see proto for format) on theFunction
definition defining the schema of the parameters of the class (names and types for now)Reasoning behind
class_parameter_schema
:The stored
class_parameter_schema
is useful/necessary for three main reasons:Feature flag
This new feature is currently gated behind the
MODAL_STRICT_PARAMETERS=1
env var and uses the existing class constructor logic but with signature inspection.When we actually release this to users (when the backend support for web parameterization is live) an idea is to instead activate strict parameters when users use a new kind of dataclass-inspired schema (which has other benefits!), and keep the unstrict behavior of custom constructors, to not break any existing user code.
Note that this is not part of this PR, just an example of how we'd introduce this in a non-breaking way:
The above syntax would let us use
typing.dataclass_transform()
to get good editor support for our classes even without explicit constructors 🤓