Repository navigation
Fix WeaveModel on non-CPU devices: register layer weights as nn.Parameter - #5190
Open
barlowa124 wants to merge 1 commit into
Open
barlowa124 wants to merge 1 commit into
barlowa124 wants to merge 1 commit into
Conversation
numpy conversion in Weave.forward WeaveLayer and WeaveGather stored their trainable weights as plain torch.Tensor attributes, so they were invisible to .to(device), the optimizer, and state_dict. The weave convolutions were frozen random projections that never trained and were never checkpointed. Weave.forward also called np.array() on inputs that TorchModel had already moved to the compute device, which raised TypeError on mps and cuda. The conversion was unnecessary since the layers call torch.tensor() on their inputs; inputs now pass through directly. Verified on Apple Silicon: all non-slow weavemodel tests pass, including three that fail on master on this hardware.
12 of 15 tasks
barlowa124
marked this pull request as ready for review
October 1, 2026 16:04
10 of 15 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The PyTorch Weave layers never registered their convolution weights as
parameters, and
Weave.forwardpushed its inputs through numpy, whichcrashes on any non-CPU device. Both are addressed here.
Weave.forwardrannp.array()on its inputs. TorchModel places themon the selected device, so under mps or cuda the call raised
TypeError(can't convert mps:0 device type tensor to numpy). Theconversion was never needed.
WeaveLayerandWeaveGatheralreadycall
torch.tensor()on what they receive, covering ndarrays andtensors alike.
WeaveLayerandWeaveGatheralso held trainable weights as plaintorch.Tensorattributes. Unregistered tensors sit outsidemodel.parameters()..to(device)skipped them andstate_dict()dropped them, so they received no gradients. On CPU this hid because
everything shared one device, but it also means the weave layers were
frozen random projections, consistent with the
test_weave_modelcomment noting a lower score than the TensorFlow equivalent.
What changed:
Weave.forwardhands its inputs to the weave layers directly.WeaveLayerandWeaveGatherarenn.Parameter.test_weave_classificationnow assigns injected weights through.data, required once the attributes became Parameters.test_weave_fit_non_cpu_devicefits a WeaveModel on theauto-selected device, reproducing the reported failure on mps/cuda
and exercising the normal path on CPU-only CI.
Old checkpoints never stored the weave weights, so
restore()understrict loading will now report missing keys on pre-change files.
strict=Falsekeeps the previous behavior.Checked on Apple Silicon (mps). The non-slow tests in
test_weavemodel_pytorch.pypass locally, including the three thatfail on master on this hardware
(
test_weave_fit_simple_distance_1,test_weave_model_reload,test_weave_singletask_classification_overfit), and the WeaveModeldocstring example runs to completion.
Type of change
Please check the option that is related to your PR.
Checklist
yapf -i <modified file>and check no errors (yapf version must be 0.32.0)mypy -p deepchemand check no errors (no new errors in modified regions, layers.py has pre-existing errors in unrelated classes)flake8 <modified file> --countand check no errorspython -m doctest <modified file>and check no errors