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

Adds warnings if automounts seem to be required #2667

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

Conversation

freider
Copy link
Contributor

@freider freider commented Dec 16, 2024

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:

  • Auto-mounting of first-party packages is disabled by default, except for the function's own package
  • Function's own package is still auto-mounted by default with the change that it will only include .py-files
  • Automounting behavior can be specified on a function and/or app level using the include_source=False flag
  • Auto-mounting can be configured to one of two values: True (new default, similar but not exactly the same as today's automount=0) and False (not even adding the function's own source package/module)

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

  • Warns users if the 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 an include_source value of True/False. This is in preparation for an upcoming deprecation of the current "auto mount" logic.

@freider freider marked this pull request as ready for review January 10, 2025 15:48
@freider freider changed the title Draft: Adds warnings if automounts seem to be required Adds warnings if automounts seem to be required Jan 13, 2025
@mwaskom
Copy link
Contributor

mwaskom commented Jan 14, 2025

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.

@freider
Copy link
Contributor Author

freider commented Jan 22, 2025

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 include_source? :)

@mwaskom
Copy link
Contributor

mwaskom commented Jan 22, 2025

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.

@freider freider changed the base branch from main to freider/auto-add-configuration January 27, 2025 12:53
Base automatically changed from freider/auto-add-configuration to main January 30, 2025 08:27
@freider freider requested a review from mwaskom January 30, 2025 12:57
@@ -435,7 +435,7 @@ def _bind_method(
return fun

@staticmethod
def from_args(
def from_local(
Copy link
Contributor Author

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":
Copy link
Contributor Author

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)

Copy link
Contributor

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)
Copy link
Contributor Author

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"
Copy link
Contributor Author

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)

Copy link
Contributor

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

Copy link
Contributor

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))
Copy link
Contributor

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"
Copy link
Contributor

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"
Copy link
Contributor

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"
Copy link
Contributor

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"..."
),
Copy link
Contributor

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"
Copy link
Contributor

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":
Copy link
Contributor

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?

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