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

Relax check_version_info to check for bytecode compatibility #41373

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

geofft
Copy link

@geofft geofft commented Nov 24, 2023

As discussed in #3988, the intention of check_version_info is to ensure that cloudpickle can transfer objects across the two Python interpreters. Because cloudpickle serializes Python bytecode, it is known to be incompatible across minor versions (e.g., 3.11 to 3.12) but should be compatible across patch versions (e.g., 3.12.0 to 3.12.1).

The intention of the CPython team is that bytecode should be compatible within patch releases to the same minor version. This was last broken in 3.5.3, which was regarded as a mistake: see the commit message of python/cpython@93602e3 (in 3.5.10), which implies that it is reasonable to "rel[y] on pre-cached bytecode remaining valid across maintenance releases."

The constant importlib.util.MAGIC_NUMBER is used by Python to identify bytecode compatibility (it is stored in .pyc files and checked when they are loaded). The unwanted change in 3.5.3 bumped MAGIC_NUMBER, but since then, it has only changed between minor versions. See the long comment in CPython's Lib/importlib/_bootstrap_external.py for a history of the changes.

So, the practical effect of checking MAGIC_NUMBER will generally be to enforce that nodes run the same minor version of Python, but if some future patch release unexpectedly does break bytecode compatibility, checking MAGIC_NUMBER will account for that.

Why are these changes needed?

This allows using interpreters at the same minor version but a different patch version, as requested in #3988.

Related issue number

Closes #3988.

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
    • but I ran black by hand
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(
    • I did some manual tests and will let CI get the rest of it.

@geofft geofft force-pushed the check-magic-number branch 2 times, most recently from 39f41bb to 10443bb Compare November 24, 2023 18:44
As discussed in ray-project#3988, the intention of check_version_info is to ensure
that cloudpickle can transfer objects across the two Python
interpreters. Because cloudpickle serializes Python bytecode, it is
known to be incompatible across minor versions (e.g., 3.11 to 3.12) but
should be compatible across patch versions (e.g., 3.12.0 to 3.12.1).

The intention of the CPython team is that bytecode should be compatible
within patch releases to the same minor version. This was last broken in
3.5.3, which was regarded as a mistake: see the commit message of
python/cpython@93602e3 (in 3.5.10),
which implies that it is reasonable to "rel[y] on pre-cached bytecode
remaining valid across maintenance releases."

The constant importlib.util.MAGIC_NUMBER is used by Python to identify
bytecode compatibility (it is stored in .pyc files and checked when they
are loaded). The unwanted change in 3.5.3 bumped MAGIC_NUMBER, but since
then, it has only changed between minor versions. See the long comment
in CPython's Lib/importlib/_bootstrap_external.py for a history of the
changes.

So, the practical effect of checking MAGIC_NUMBER will generally be to
enforce that nodes run the same minor version of Python, but if some
future patch release unexpectedly does break bytecode compatibility,
checking MAGIC_NUMBER will account for that.

Signed-off-by: Geoffrey Thomas <[email protected]>
@jjyao
Copy link
Collaborator

jjyao commented Nov 27, 2023

Your explanation makes sense to me. But I think we need to get some confirmation from cloudpickle devs saying that checking MAGIC_NUMBER is enough? cc @pcmoritz

@rkooo567 rkooo567 self-assigned this Nov 28, 2023
@anyscalesam anyscalesam added triage Needs triage (eg: priority, bug/not-bug, and owning component) core Issues that should be addressed in Ray Core labels May 14, 2024
@jjyao jjyao added P1 Issue that should be fixed within a few weeks and removed triage Needs triage (eg: priority, bug/not-bug, and owning component) labels Sep 16, 2024
@SebastianMorawiec
Copy link

@jjyao
This Pr would help a lot with collaboration between workers with different patch versions of Python. Are there any plans to merge it in anytime soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues that should be addressed in Ray Core P1 Issue that should be fixed within a few weeks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can I ignore python version mismatch?
6 participants