-
Notifications
You must be signed in to change notification settings - Fork 43
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
Adds warnings if automounts seem to be required #2667
base: main
Are you sure you want to change the base?
Conversation
…ge-mount-warnings
…nts (since it is added by another path)
…ge-mount-warnings
FWIW I think it's fine to keep "automount" as the terminology. As a standalone verb I think it's a little more clear; "add" could mean so many things. |
What about |
That could work too, although I think "auto" is helpfully communicating something in the current name. But maybe less helpful in an explicit parameter than in a config setting I guess. |
…ckage-mount-warnings
…ckage-mount-warnings
…ckage-mount-warnings
…ckage-mount-warnings
modal/functions.py
Outdated
@@ -435,7 +435,7 @@ def _bind_method( | |||
return fun | |||
|
|||
@staticmethod | |||
def from_args( | |||
def from_local( |
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.
Semi-unrelated, but I've been wanting to do this rename, and since I replaced _from_args
usage in Image I changed this while I was at it...
img.force_build = force_build | ||
return img | ||
|
||
def _extend(self, **kwargs) -> "_Image": |
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.
I think we used to have this as a public (?) method, but removed/deprecated it. Now I needed a new private version of it to make it more ergonomic to transfer attributes from parent layers to children (_added_python_source_set
in this case)
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.
Is there some reason Image._from_args
can't automatically transfer the added source set from the provided base Image?
@@ -843,7 +853,9 @@ def add_local_python_source( | |||
``` | |||
""" | |||
mount = _Mount._from_local_python_packages(*modules, ignore=ignore) | |||
return self._add_mount_layer_or_copy(mount, copy=copy) | |||
img = self._add_mount_layer_or_copy(mount, copy=copy) | |||
img._added_python_source_set |= set(modules) |
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 the key part of this change - track all add_local_python_source
modules on the Image objects so we can inspect it later when the automount logic executes to see which modules are missing. It's not perfect, but people can get rid of false positive warnings by setting include_source
to any boolean value (with the expectation that they know what they are doing)
deprecation_warning( | ||
(2024, 1, 31), | ||
( | ||
"Automatic adding of local python source will be deprecated in the future.\n" |
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.
@mwaskom let me know if you have ideas for other ways of phrasing this, and if we should mention the include_source
option or not (I'm leaning towards no since it's not typically needed)
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.
Yeah I think that include_source
is not relevant at this stage of the deprecation process; advising users on how to update their Image definitions
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.
Suggested rephrasing of the prose:
Modal will stop implicitly adding local Python modules to the Image ("automounting") in a future update. The following modules need to be explicitly added for future compatibility:
f"Make sure you have explicitly added the source for the following modules to the Image " | ||
f"used by `{info.function_name}`:\n" | ||
) | ||
+ ", ".join(sorted(warn_missing_modules)) |
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.
Nit: can we make this a bulleted list? It looks visually strange for a single module imo:
╭─ Modal Deprecation Warning (2024-01-31) ───────────────────────────────────────────────────────────────╮
│ Automatic adding of local python source will be deprecated in the future. │
│ Make sure you have explicitly added the source for the following modules to the Image used by `f`: │
│ helper │
│ │
│ e.g.: │
+ "\n\n" | ||
+ ( | ||
"e.g.:\n" | ||
f"image = Image.debian_slim().add_local_python_source" |
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.
I'm a little worried about this tripping up an overly-literal user who has an Image based on something other than .debian_slim
(). I don't know that we have a great way to show a more app-tuned suggestion though since we don't track the Image constructor that was used in an explicit way.
deprecation_warning( | ||
(2024, 1, 31), | ||
( | ||
"Automatic adding of local python source will be deprecated in the future.\n" |
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.
Yeah I think that include_source
is not relevant at this stage of the deprecation process; advising users on how to update their Image definitions
"e.g.:\n" | ||
f"image = Image.debian_slim().add_local_python_source" | ||
f"({python_stringified_modules})\n" | ||
f"@app.function(image=image)\n" |
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.
Likewise I'm a little worried about a literal-minded user thinking this change requires the Image to be passed directly to the function (and not the App constructor)
I think it's fine for the suggestion just to demonstrate the Image construction syntax and now how you'd use it.
f"({python_stringified_modules})\n" | ||
f"@app.function(image=image)\n" | ||
f"..." | ||
), |
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.
Can we add a line like "For more information, see https://modal.com/docs/guide/modal-1-0-migration"? When users start seeing all the new deprecation warnings I think it will be helpful to call their attention to the idea that this is "one last hurrah" to manage their annoyance :D.
We can also add a more verbose explanation of what's going on and the various options for ameliorating it there. I can work on that.
deprecation_warning( | ||
(2024, 1, 31), | ||
( | ||
"Automatic adding of local python source will be deprecated in the future.\n" |
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.
Suggested rephrasing of the prose:
Modal will stop implicitly adding local Python modules to the Image ("automounting") in a future update. The following modules need to be explicitly added for future compatibility:
img.force_build = force_build | ||
return img | ||
|
||
def _extend(self, **kwargs) -> "_Image": |
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.
Is there some reason Image._from_args
can't automatically transfer the added source set from the provided base Image?
Adds a warning when packages from global scope imports haven't been added to an image using
.add_local_python_source
if using the not setting an explicit include_source mode, and not using MODAL_AUTOMOUNT=0.This will be used in a longer transition period towards deprecation of "auto mounting", getting us to a future with the following standard:
include_source=False
flagCheck these boxes or delete any item (or this section) if not relevant for this PR.
Note on protobuf: protobuf message changes in one place may have impact to
multiple entities (client, server, worker, database). See points above.
Changelog
modal.Image
of a Function/Cls doesn't include all the globally imported "local" modules (using.add_local_python_source()
), and the user hasn't explicitly set aninclude_source
value of True/False. This is in preparation for an upcoming deprecation of the current "auto mount" logic.