-
Notifications
You must be signed in to change notification settings - Fork 38
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
run_function return type specificity #2428
base: main
Are you sure you want to change the base?
Conversation
@@ -1396,7 +1396,7 @@ def build_dockerfile(version: ImageBuilderVersion) -> DockerfileSpec: | |||
|
|||
def run_function( | |||
self, | |||
raw_f: Callable[..., Any], | |||
raw_f: Callable[..., None], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a narrowing but I can't think of a case where returning something is desired. These should just be side-effect functions.
I could imagine users doing something like this def load_model_with_caching():
return transformers.AutoModel.from_pretrained("whatever-bert")
image = modal.Image.debian_slim().run_function(load_model_with_caching)
...
@app.function()
def do_inference(input):
model = load_model_with_caching()
model(input) Similar to our advertised "stack Still it's helpful to clarify that we don't use the return value. Maybe that could just be done with narrative documentation? Not sure. |
Yeh I think I've even done something similar myself. But the problem is that in the |
I guess it wouldn't be trivial not to do this since the container doesn't know it's running a "build function"? |
It might actually be easy enough. I think the container can access the Function definition which has something like |
Good point, if it's not too hard structurally in the container entrypoint we should add something that just returns None as the result value when running a builder function! I've ran into this issue where builds take ages because of doing things like |
Describe your changes
context: https://modal-com.slack.com/archives/C06UKEPF3HR/p1730314009504369
Backward/forward compatibility checks
Just a type-checking change and docs change.
Check these boxes or delete any item (or this section) if not relevant for this PR.