Skip to content

Commit 9209681

Browse files
committed
Merge branch 'hotfix/model-device-auto-error' into 'export/v1-2-2'
Fix `device="auto"` crash in evaluation See merge request onecomp/onecomp-lab!96
2 parents 70e8905 + ea8c3f1 commit 9209681

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change log
22

3+
## [v1.2.2] 2026-07-10
4+
5+
### Bug Fix
6+
7+
- Fixed `device="auto"` evaluation crashes in `Runner.calculate_perplexity()` and related paths by adding `ModelConfig.get_device()` and using a resolved `torch.device` for PyTorch operations such as `model.to()` and `empty_cache()`. Hugging Face `device_map="auto"` remains unchanged for model loading, but PyTorch no longer receives the raw `"auto"` string.
8+
39
## [v1.2.1] 2026-07-03
410

511
### Security

onecomp/model_config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import torch
1212
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
1313

14+
from .utils.device import get_default_device
1415
from .utils.dtype import needs_bfloat16
1516

1617
try:
@@ -114,6 +115,12 @@ def load_model(self, device_map=None):
114115
self.logger.info("Model loaded with dtype=%s", next(model.parameters()).dtype)
115116
return model
116117

118+
def get_device(self) -> torch.device:
119+
"""Return a concrete torch.device for PyTorch operations."""
120+
if self.device == "auto":
121+
return get_default_device()
122+
return torch.device(self.device)
123+
117124
def load_tokenizer(self):
118125
"""Load the tokenizer"""
119126

onecomp/runner.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def check(self):
327327

328328
# MPS device validation: only GPTQ (or AutoBitQuantizer whose
329329
# candidates are all GPTQ, without DBF fallback) is supported on MPS
330-
device = self.model_config.device
330+
device = self.model_config.get_device()
331331
if is_mps_device(device):
332332
if self.multi_gpu:
333333
raise ValueError("multi_gpu is not supported on MPS device.")
@@ -1139,24 +1139,24 @@ def _calculate_evaluation(
11391139
tokenizer = self.model_config.load_tokenizer()
11401140
original_result = eval_function(model=model, tokenizer=tokenizer, **eval_args)
11411141
del model, tokenizer
1142-
empty_cache(self.model_config.device)
1142+
empty_cache(self.model_config.get_device())
11431143

11441144
if quantized_model:
11451145
try:
11461146
logger.info("Evaluating quantized model (%s)...", eval_name)
11471147
if self.quantized_model is not None:
11481148
model = self.quantized_model
1149-
model.to(self.model_config.device)
1149+
model.to(self.model_config.get_device())
11501150
tokenizer = self.model_config.load_tokenizer()
11511151
quantized_result = eval_function(model=model, tokenizer=tokenizer, **eval_args)
11521152
model.to("cpu")
11531153
del tokenizer
11541154
else:
11551155
model, tokenizer = self.create_quantized_model(quantizer=quantizer)
1156-
model.to(self.model_config.device)
1156+
model.to(self.model_config.get_device())
11571157
quantized_result = eval_function(model=model, tokenizer=tokenizer, **eval_args)
11581158
del model, tokenizer
1159-
empty_cache(self.model_config.device)
1159+
empty_cache(self.model_config.get_device())
11601160
except NotImplementedError:
11611161
logger.warning(
11621162
"This quantization method does not support creating a quantized model; "
@@ -1171,7 +1171,7 @@ def _calculate_evaluation(
11711171
self.update_model_weights(model, quantizer=quantizer)
11721172
dequantized_result = eval_function(model=model, tokenizer=tokenizer, **eval_args)
11731173
del model, tokenizer
1174-
empty_cache(self.model_config.device)
1174+
empty_cache(self.model_config.get_device())
11751175

11761176
return original_result, dequantized_result, quantized_result
11771177

@@ -2117,7 +2117,7 @@ def analyze_cumulative_error(
21172117
)
21182118
# Release fragmented GPU memory from previous operations (e.g., run())
21192119
gc.collect()
2120-
empty_cache(self.model_config.device)
2120+
empty_cache(self.model_config.get_device())
21212121

21222122
model = self.model_config.load_model()
21232123
input_device = next(model.parameters()).device
@@ -2141,7 +2141,7 @@ def analyze_cumulative_error(
21412141
)
21422142
# Release fragmented GPU memory from previous operations (e.g., run())
21432143
gc.collect()
2144-
empty_cache(self.model_config.device)
2144+
empty_cache(self.model_config.get_device())
21452145

21462146
model = self.model_config.load_model()
21472147
input_device = next(model.parameters()).device

0 commit comments

Comments
 (0)