Skip to content

Fix loading state dict for SingleTaskVariationalGP/ApproximateGPyTorchModel (#3251)#3251

Open
esantorella wants to merge 1 commit into
meta-pytorch:mainfrom
esantorella:export-D98021112
Open

Fix loading state dict for SingleTaskVariationalGP/ApproximateGPyTorchModel (#3251)#3251
esantorella wants to merge 1 commit into
meta-pytorch:mainfrom
esantorella:export-D98021112

Conversation

@esantorella
Copy link
Copy Markdown
Contributor

@esantorella esantorella commented Mar 24, 2026

Summary:

Context: See https://github.com/meta-pytorch/botorch/issues/3250 .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its model attribute (e.g. model.model.train_targets).

Changes:

  • Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: None typing effectively replaces hasattr checks for train_targets
  • Used these methods in load_state_dict
  • Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112

@meta-cla meta-cla Bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Mar 24, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Mar 24, 2026

@esantorella has exported this pull request. If you are a Meta employee, you can view the originating Diff in D98021112.

@meta-codesync meta-codesync Bot changed the title Fix loading state dict for SingleTaskVariationalGP/ApproximateGPyTorchModel Fix loading state dict for SingleTaskVariationalGP/ApproximateGPyTorchModel (#3251) Mar 26, 2026
esantorella added a commit to esantorella/botorch that referenced this pull request Mar 26, 2026
…hModel (meta-pytorch#3251)

Summary:

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
esantorella added a commit to esantorella/botorch that referenced this pull request Mar 26, 2026
…hModel (meta-pytorch#3251)

Summary:
Pull Request resolved: meta-pytorch#3251

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
esantorella added a commit to esantorella/botorch that referenced this pull request Mar 26, 2026
…hModel (meta-pytorch#3251)

Summary:

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
esantorella added a commit to esantorella/botorch that referenced this pull request Mar 26, 2026
…hModel (meta-pytorch#3251)

Summary:

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
esantorella added a commit to esantorella/botorch that referenced this pull request Mar 26, 2026
…hModel (meta-pytorch#3251)

Summary:

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
esantorella added a commit to esantorella/botorch that referenced this pull request Mar 26, 2026
…hModel (meta-pytorch#3251)

Summary:
Pull Request resolved: meta-pytorch#3251

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
esantorella added a commit to esantorella/botorch that referenced this pull request Mar 26, 2026
…hModel (meta-pytorch#3251)

Summary:
Pull Request resolved: meta-pytorch#3251

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
esantorella added a commit to esantorella/botorch that referenced this pull request Mar 26, 2026
…hModel (meta-pytorch#3251)

Summary:
Pull Request resolved: meta-pytorch#3251

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.98%. Comparing base (42facfa) to head (cfe0514).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3251   +/-   ##
=======================================
  Coverage   99.98%   99.98%           
=======================================
  Files         220      220           
  Lines       21871    21890   +19     
=======================================
+ Hits        21867    21886   +19     
  Misses          4        4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

esantorella added a commit to esantorella/botorch that referenced this pull request Mar 26, 2026
…hModel (meta-pytorch#3251)

Summary:

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
esantorella added a commit to esantorella/botorch that referenced this pull request Mar 26, 2026
…hModel (meta-pytorch#3251)

Summary:
Pull Request resolved: meta-pytorch#3251

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
esantorella added a commit to esantorella/botorch that referenced this pull request Mar 27, 2026
…hModel (meta-pytorch#3251)

Summary:

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
…hModel (meta-pytorch#3251)

Summary:
Pull Request resolved: meta-pytorch#3251

**Context**: See `https://github.com/meta-pytorch/botorch/issues/3250` .

GPyTorchModel.load_state_dict previously accessed self.train_targets and self.train_inputs unconditionally, which failed for ApproximateGPyTorchModel because its training data lives on its `model` attribute (e.g. `model.model.train_targets`).

**Changes**:
- Extracted two new overridable methods on GPyTorchModel: _untransform_targets() (undo outcome transform and return raw targets) and _retransform_and_set_targets(). Note: `None` typing effectively replaces `hasattr` checks for `train_targets`
- Used these methods in `load_state_dict`
- Overrode both methods on ApproximateGPyTorchModel to read from / write to self.model.train_targets and self.model.train_inputs instead of self.

Differential Revision: D98021112
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant