Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI-319: Add support for custom pickle type to parameterized functions #2806

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

kramstrom
Copy link
Contributor

@kramstrom kramstrom commented Jan 24, 2025

Describe your changes

Do not merge -- need to merge backend support before this.

  • Adds support for new modal.parameter types other than int and str by adding a "catch-all" type that pickles whatever the user sends in.
  • Renamed parametrized to parameterized across codebase

Usage:

@app.cls()
class C:
    a: typing.Annotated[list, modal.PickleSerialization] = modal.parameter(default=[1, 2, 3])
  • Provide Linear issue reference (e.g. MOD-1234) if available.
Backward/forward compatibility checks

Check these boxes or delete any item (or this section) if not relevant for this PR.

  • Client+Server: this change is compatible with old servers
  • Client forward compatibility: this change ensures client can accept data intended for later versions of itself

Note on protobuf: protobuf message changes in one place may have impact to
multiple entities (client, server, worker, database). See points above.


Changelog

Adds support for custom types for parameterized functions.

Usage:

import typing
import modal

app = modal.App()


@app.cls()
class Foo:
    a: typing.Annotated[dict, modal.PickleSerialization] = modal.parameter()
    b: typing.Annotated[list, modal.PickleSerialization] = modal.parameter(default=[1, 2, 3])

    @modal.method()
    def bar(self):
        return f"hello {self.a}, {self.b}"


@app.local_entrypoint()
def main():
    foo = Foo(a={"foo": "bar"})
    foo.bar.remote()

For parameterized functions with web hooks you must provide a default value to any custom type parameter and these parameters cannot be overridden with web parameter inputs.

modal/cls.py Outdated Show resolved Hide resolved
@kramstrom kramstrom requested review from freider and mwaskom January 24, 2025 13:20
test/cls_test.py Outdated Show resolved Hide resolved
@kramstrom kramstrom changed the title [WIP] CLI-319: Add support for Any type to parameterized functions [WIP] CLI-319: Add support for custom pickle type to parameterized functions Jan 24, 2025
@kramstrom kramstrom force-pushed the kramstrom/cli-319-add-support-for-any-type-to-parameterized-functions branch from 1663ffe to 7c81fc8 Compare January 27, 2025 13:12
add test

typing.Annotated

Rename SandboxSnapshotFromId to SandboxSnapshotGet (#2800)

rename SandboxSnapshotFromId

[auto-commit] [skip ci] Bump the build number

Enable sandbox tests on mac (#2808)

* Enable sandbox tests on mac

* update scheduler placement test

* remove unused import

[auto-commit] [skip ci] Bump the build number
@kramstrom kramstrom force-pushed the kramstrom/cli-319-add-support-for-any-type-to-parameterized-functions branch from 7c81fc8 to b6dfc0d Compare January 27, 2025 13:12
@kramstrom kramstrom marked this pull request as ready for review January 28, 2025 10:36
@kramstrom kramstrom requested a review from freider January 28, 2025 10:36
@kramstrom kramstrom changed the title [WIP] CLI-319: Add support for custom pickle type to parameterized functions CLI-319: Add support for custom pickle type to parameterized functions Jan 28, 2025
@kramstrom kramstrom requested a review from freider January 29, 2025 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants