Skip to content

build(deps): cap NumPy below 2 in the onnx extra - #947

Merged
NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
thread3d:build/onnx-numpy-cap
Oct 7, 2026
Merged

NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
thread3d:build/onnx-numpy-cap

Conversation

@thread3d

@thread3d thread3d commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

pip install laya[onnx] resolves onnx, whose ml-dtypes dependency pulls NumPy 2.
torch below 2.3 is built against NumPy 1.x and raises "Numpy is not available" when it
converts a tensor against 2.x -- which predict() needs for its final .numpy().

pyproject.toml declares torch>=2.0.0, so the extra should not force a NumPy the
declared floor cannot use. NumPy 1.26 satisfies onnx, onnxruntime and onnxscript, so the
cap costs the ONNX path nothing.

Found while running the ONNX path on the macOS/Intel stack, which pins torch 2.2.2 and
NumPy 1.26 for exactly this reason.

@NandhaKishorM

Copy link
Copy Markdown
Owner

Holding this one for a narrower form, and the other three in your set are merged: #945, #946 and #949, plus #948.

The diagnosis is right and worth stating again because it is not obvious. pip install laya[onnx] resolving onnx pulls ml-dtypes which pulls NumPy 2, torch below 2.3 is built against NumPy 1.x, and predict() needs a final .numpy(), so the extra as written cannot be installed against the bottom of our own declared torch>=2.0.0 range. That is a real contradiction in pyproject.toml and it should not stand.

My problem is the blast radius of the fix. numpy<2 in the extra applies to everyone who installs laya[onnx], including the majority on a current torch who have no reason to be held to NumPy 1.x, and a hard upper cap is the one kind of constraint that breaks resolution for unrelated reasons: any other package in the environment that requires numpy>=2 now makes laya[onnx] uninstallable rather than merely suboptimal. Trading a failure at the declared floor for a resolution failure at the top is not clearly the better side.

An environment marker gets the same result without the cost, since the stack this actually affects is identifiable:

onnx = ["onnx", "onnxruntime", "onnxscript",
        "numpy<2; platform_system == 'Darwin' and platform_machine == 'x86_64'"]

That is exactly the macOS Intel checkout from #948, where torch tops out at 2.2.2 and the cap is genuinely required, and it leaves every other platform resolving whatever onnx wants. If you would rather not key on the platform, the alternative is to leave the extra alone and raise the floor to torch>=2.3 where the ONNX path is concerned, but that is a larger decision than this PR.

Either shape is fine by me. Push the marker version and I will merge it, and keep the comment you wrote, since the reason for the constraint is the part nobody would reconstruct later.

One correction to the body for whoever reads it next: NumPy 1.26 satisfying onnx, onnxruntime and onnxscript is true today and is the kind of thing that stops being true, so the marker form also means we are not quietly pinning three packages' futures to it.

`pip install laya[onnx]` resolves `onnx`, whose `ml-dtypes` dependency pulls NumPy 2.
torch below 2.3 is built against NumPy 1.x and raises "Numpy is not available" when it
converts a tensor against 2.x, which `predict()` needs for its final `.numpy()`. The
package declares `torch>=2.0.0`, so the extra should not force a NumPy the declared
floor cannot use.

Scope the cap with an environment marker rather than a blanket `numpy<2`: a hard upper
cap binds every `laya[onnx]` install, including the many on a current torch, and makes
the extra unresolvable next to any package that requires `numpy>=2`. The marker names
the stack this actually affects -- the macOS/Intel checkout (NandhaKishorM#948), where torch tops
out at 2.2.2 and NumPy 1.26 satisfies onnx, onnxruntime and onnxscript anyway.
@thread3d
thread3d force-pushed the build/onnx-numpy-cap branch from 55e59f2 to 495b590 Compare October 6, 2026 08:03
@thread3d

thread3d commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Pushed the marker form:

onnx = ["onnx", "onnxruntime", "onnxscript",
        "numpy<2; platform_system == 'Darwin' and platform_machine == 'x86_64'"]

The reason comment stays, extended to say why the cap is marker-scoped rather than blanket: the failure at torch>=2.0.0's bottom is real, but trading it for an unresolvable extra against anything requiring numpy>=2 is not clearly better, and the stack that actually needs the cap is identifiable.

Checked before pushing: the marker evaluates true only for Darwin/x86_64 and false for Darwin/arm64, Linux/x86_64 and Windows/AMD64; tests/test_packaging.py passes 136/136 in a clean checkout, with ruff and compileall clean. Thanks for the correction on the top end — the resolution failure is the half I had not weighed.

@NandhaKishorM
NandhaKishorM merged commit 87e445d into NandhaKishorM:main Oct 7, 2026
30 checks passed
@NandhaKishorM

Copy link
Copy Markdown
Owner

Merged in 0.3.29. This is exactly the form I asked for, and the comment is better than the one I suggested.

onnx = ["onnx", "onnxruntime", "onnxscript",
        "numpy<2; platform_system == 'Darwin' and platform_machine == 'x86_64'"]

The marker names the stack that needs the cap and leaves everyone else resolving what onnx wants, so the contradiction at the bottom of our declared torch>=2.0.0 range is fixed without making the extra unresolvable next to anything requiring numpy>=2.

Checking that the marker evaluates true only for Darwin x86_64 and false for Darwin arm64, Linux x86_64 and Windows AMD64 before pushing is the verification this needed, since a marker that is wrong in either direction fails silently: too narrow and the original bug stays, too broad and we are back to the blanket cap with extra steps.

Your comment also keeps the point I made about the top end, that NumPy 1.26 satisfying those three packages is true today and is the kind of thing that stops being true, so the marker form means we are not quietly pinning three packages' futures on behalf of one platform. That sentence is the reason the constraint will still make sense to whoever reads it in a year, which is the whole job of a comment on a dependency pin.

Thanks for taking the correction on the resolution failure rather than defending the original. That is the half I would have missed if you had not written the diagnosis out first.

All 83 suites pass on the merged tree, and this is live in the published 0.3.29 wheel.

@thread3d
thread3d deleted the build/onnx-numpy-cap branch October 7, 2026 11:52
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