-
Notifications
You must be signed in to change notification settings - Fork 20
Fix non-QEP Runner quantization for large sharded MPS checkpoints #61
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
Merged
aki916f
merged 10 commits into
FujitsuResearch:develop/v1-3-4
from
y-vectorfield:fix_runner_behavior_on_mps
Sep 14, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0715e9d
Fix Runner behavio on MPS
y-vectorfield 9666baf
Reflect review comments: Add test
y-vectorfield dece6dc
Reflect reviw comments
y-vectorfield 3ba8978
Reflect review comments
y-vectorfield 848fcfa
Modify chunked quantization
y-vectorfield 65253cf
Modify CHANGELOG
y-vectorfield f91ab46
Reflect review comments
y-vectorfield b4b46d9
Reflect additional review comments
y-vectorfield 9c34d5e
Reflect additional review comments
y-vectorfield 957f9ea
Modify test model config
y-vectorfield File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| """Unit tests for ModelConfig MPS model-loading behavior. | ||
|
|
||
| Copyright 2025-2026 Fujitsu Ltd. | ||
|
|
||
| Author: Yuhki Yano | ||
| """ | ||
|
|
||
| from types import SimpleNamespace | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from onecomp.model_config import ModelConfig | ||
|
|
||
|
|
||
| def _mock_loaded_model(): | ||
| model = MagicMock(name="model") | ||
| model.parameters.side_effect = lambda: iter([torch.empty(1, dtype=torch.float16)]) | ||
| model.to.return_value = model | ||
| return model | ||
|
|
||
|
|
||
| def test_load_model_loads_mps_model_on_cpu_then_moves_to_mps(monkeypatch): | ||
| """MPS loads sharded checkpoints on CPU before moving the model to MPS.""" | ||
| model = _mock_loaded_model() | ||
| config = SimpleNamespace(quantization_config=None) | ||
|
|
||
| load_config = MagicMock(return_value=config) | ||
| load_model = MagicMock(return_value=model) | ||
|
|
||
| monkeypatch.setattr("onecomp.model_config.AutoConfig.from_pretrained", load_config) | ||
| monkeypatch.setattr( | ||
| "onecomp.model_config.AutoModelForCausalLM.from_pretrained", | ||
| load_model, | ||
| ) | ||
|
|
||
| model_config = ModelConfig(model_id="test/model", device="mps") | ||
| loaded = model_config.load_model() | ||
|
|
||
| assert loaded is model | ||
| load_model.assert_called_once_with( | ||
| "test/model", | ||
| dtype=torch.float16, | ||
| device_map="cpu", | ||
| ) | ||
| model.to.assert_called_once_with("mps") | ||
| model.eval.assert_called_once_with() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("device", ["cpu", "cuda:0"]) | ||
| def test_load_model_preserves_explicit_no_mps_device_map(monkeypatch, device): | ||
| """Explicit non-MPS device maps are passed through unchanged.""" | ||
| model = _mock_loaded_model() | ||
| config = SimpleNamespace(quantization_config=None) | ||
|
|
||
| monkeypatch.setattr( | ||
| "onecomp.model_config.AutoConfig.from_pretrained", | ||
| MagicMock(return_value=config), | ||
| ) | ||
| load_model = MagicMock(return_value=model) | ||
| monkeypatch.setattr( | ||
| "onecomp.model_config.AutoModelForCausalLM.from_pretrained", | ||
| load_model, | ||
| ) | ||
|
|
||
| model_config = ModelConfig(model_id="test/model", device=device) | ||
| model_config.load_model() | ||
|
|
||
| load_model.assert_called_once_with( | ||
| "test/model", | ||
| dtype=torch.float16, | ||
| device_map=device, | ||
| ) | ||
| model.to.assert_not_called() | ||
| model.eval.assert_called_once_with() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "resolved_device, expected_device_map", | ||
| [ | ||
| (torch.device("cpu"), "auto"), | ||
| (torch.device("mps"), "cpu"), | ||
| ], | ||
| ) | ||
| def test_load_model_auto_preserves_device_map(monkeypatch, resolved_device, expected_device_map): | ||
| """device='auto' keeps Transformers auto placement unless MPS is selected.""" | ||
| model = _mock_loaded_model() | ||
| config = SimpleNamespace(quantization_config=None) | ||
| load_model = MagicMock(return_value=model) | ||
| monkeypatch.setattr( | ||
| "onecomp.model_config.AutoConfig.from_pretrained", | ||
| MagicMock(return_value=config), | ||
| ) | ||
| monkeypatch.setattr( | ||
| "onecomp.model_config.AutoModelForCausalLM.from_pretrained", | ||
| load_model, | ||
| ) | ||
| monkeypatch.setattr( | ||
| "onecomp.model_config.get_default_device", | ||
| MagicMock(return_value=resolved_device), | ||
| ) | ||
| ModelConfig(model_id="test/model", device="auto").load_model() | ||
|
|
||
| load_model.assert_called_once_with( | ||
| "test/model", | ||
| dtype=torch.float16, | ||
| device_map=expected_device_map, | ||
| ) | ||
| if resolved_device.type == "mps": | ||
| model.to.assert_called_once_with(resolved_device) | ||
| else: | ||
| model.to.assert_not_called() | ||
| model.eval.assert_called_once_with() |
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
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.
Uh oh!
There was an error while loading. Please reload this page.