Skip to content

Commit beebe48

Browse files
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent a5d845c commit beebe48

4 files changed

Lines changed: 9 additions & 6 deletions

File tree

superbench/benchmarks/micro_benchmarks/_export_torch_to_onnx.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
class torch2onnxExporter():
2020
"""PyTorch model to ONNX exporter."""
21-
2221
def __init__(self):
2322
"""Constructor."""
2423
from transformers import BertConfig, GPT2Config, LlamaConfig
@@ -360,7 +359,6 @@ def _build_vision_export_inputs(self, model, batch_size, model_dtype, device):
360359
dynamic_axes = {'pixel_values': {0: 'batch_size'}, 'output': {0: 'batch_size'}}
361360

362361
class VisionModelWrapper(torch.nn.Module):
363-
364362
def __init__(self, model):
365363
super().__init__()
366364
self.model = model
@@ -398,7 +396,6 @@ def _build_nlp_export_inputs(self, model, batch_size, seq_length, device):
398396
}
399397

400398
class NLPModelWrapper(torch.nn.Module):
401-
402399
def __init__(self, model):
403400
super().__init__()
404401
self.model = model

superbench/benchmarks/micro_benchmarks/huggingface_model_loader.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@ def load_model(
154154
# Reject malformed / path-like identifiers before any network or disk activity.
155155
validate_model_identifier(model_identifier)
156156

157+
# Fall back to CPU on hosts without CUDA so default device='cuda' callers don't fail.
158+
if device == 'cuda' and not torch.cuda.is_available():
159+
logger.warning('CUDA not available; falling back to CPU.')
160+
device = 'cpu'
161+
157162
try:
158163
load_kwargs = self._build_load_kwargs(torch_dtype, revision, kwargs)
159164

superbench/benchmarks/micro_benchmarks/tensorrt_inference_performance.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
class TensorRTInferenceBenchmark(MicroBenchmarkWithInvoke):
2525
"""TensorRT inference micro-benchmark class."""
26+
2627
def __init__(self, name, parameters=''):
2728
"""Constructor.
2829
@@ -238,9 +239,10 @@ def _preprocess_huggingface_models(self):
238239
hf_config = AutoConfig.from_pretrained(
239240
self._args.model_identifier, trust_remote_code=allow_remote_code, **load_kwargs
240241
)
241-
precision_str = self._args.precision # already a string: 'fp16', 'fp32', 'int8'
242+
# ONNX export is always done in float32 (see _build_trtexec_command_for_hf), so gate
243+
# the pre-download check on fp32 memory regardless of the requested runtime precision.
242244
fits, _, _, _ = HuggingFaceModelLoader.check_memory_fits(
243-
self._args.model_identifier, hf_config, precision_str, mode='inference', token=hf_token
245+
self._args.model_identifier, hf_config, 'fp32', mode='inference', token=hf_token
244246
)
245247
if not fits:
246248
self._result.set_return_code(ReturnCode.MICROBENCHMARK_EXECUTION_FAILURE)

tests/benchmarks/micro_benchmarks/test_huggingface_e2e.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
)
2929
class TestHuggingFaceE2E:
3030
"""End-to-end tests for HuggingFace model loading."""
31-
3231
@pytest.fixture
3332
def loader(self, tmp_path):
3433
"""Create a loader instance with an isolated per-test cache dir."""

0 commit comments

Comments
 (0)