Repository navigation
Conversation
_to_helper returns None for the dtype (device) if only a device (dtype) is passed to to(), but several to() overrides did not handle that: - InterpolatedLinearOperator.to and MaskedLinearOperator.to evaluated dtype.is_floating_point and raised "AttributeError: 'NoneType' object has no attribute 'is_floating_point'" for e.g. op.to(device="cpu"). This also broke indexing a CatLinearOperator of such operators, which calls .to(output_device) on the selected operator. - IdentityLinearOperator.to set the dtype (device) to None, so op.to(device) evaluated in the default dtype instead of op.dtype, and op.to(dtype) moved a CUDA operator to the CPU. - CatLinearOperator.to set output_device to None if only a dtype is given. Only move the device if no dtype is given, and keep the current dtype, device or output device if it is not given. Add a test to LinearOperatorTestCase that calls to() with only a device and only a dtype, and a test that indexes a CatLinearOperator of InterpolatedLinearOperators. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #141.
Problem
_to_helperreturnsNonefor the dtype (device) if only a device (dtype) is passed toto(), but severalto()overrides did not handle that:InterpolatedLinearOperator.toandMaskedLinearOperator.toraisedAttributeError: 'NoneType' object has no attribute 'is_floating_point'for e.g.op.to(device="cpu"). This also broke indexing aCatLinearOperatorof such operators, which calls.to(output_device)on the selected operator (Fix scalarize_posterior for interpolated covariance blocks meta-pytorch/botorch#3408).IdentityLinearOperator.toset the dtype (device) toNone, soop.to(device)evaluated in the default dtype instead ofop.dtype, andop.to(dtype)moved a CUDA operator to the CPU.CatLinearOperator.tosetoutput_devicetoNoneif only a dtype was given.Change
Only move the device if no dtype is given (as #133 proposed for
MaskedLinearOperator), and keep the current dtype, device or output device if it is not given.Tests
LinearOperatorTestCase.test_to_device_or_dtype_onlycallsto()with only a device (positional and keyword) and with only a dtype, and checks dtype, device and values. Onmainit fails for all 12 Interpolated, Masked, Identity and Cat test classes (75 classes run it).TestInterpolatedLinearOperator.test_getitem_catindexes aCatLinearOperatorofInterpolatedLinearOperators.Full suite: 5122 tests pass, except
test_psd_safe_cholesky_psd, which also fails onmainlocally (torch 2.13 on Windows, unrelated). I also checked CUDA round trips (.to(cuda),.to(torch.float32),.to(device="cpu")) for the four operators manually. flake8 passes. Tested with Python 3.13, PyTorch 2.13.🤖 Generated with Claude Code