Skip to content
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

Fix mlserver_huggingface settings device type #1486

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions runtimes/huggingface/mlserver_huggingface/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ class Config:
runtime.
"""

device: int = -1
device: Optional[Union[int, str]] = None
"""
Device in which this pipeline will be loaded (e.g., "cpu", "cuda:1", "mps",
or a GPU ordinal rank like 1).
or a GPU ordinal rank like 1). Default value of None becomes cpu.
"""

inter_op_threads: Optional[int] = None
Expand Down
39 changes: 38 additions & 1 deletion runtimes/huggingface/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
import torch
from typing import Dict, Optional
from typing import Dict, Optional, Union
from optimum.onnxruntime.modeling_ort import ORTModelForQuestionAnswering
from transformers.models.distilbert.modeling_distilbert import (
DistilBertForQuestionAnswering,
Expand Down Expand Up @@ -169,6 +169,43 @@ def test_pipeline_uses_model_kwargs(
assert m.model.dtype == expected


@pytest.mark.parametrize(
"pretrained_model, device, expected",
[
(
"hf-internal-testing/tiny-bert-for-token-classification",
None,
torch.device("cpu"),
),
(
"hf-internal-testing/tiny-bert-for-token-classification",
-1,
torch.device("cpu"),
),
(
"hf-internal-testing/tiny-bert-for-token-classification",
"cpu",
torch.device("cpu"),
),
],
)
def test_pipeline_cpu_device_set(
pretrained_model: str,
device: Optional[Union[str, int]],
expected: torch.device,
):
hf_settings = HuggingFaceSettings(
pretrained_model=pretrained_model, task="token-classification", device=device
)
model_settings = ModelSettings(
name="foo",
implementation=HuggingFaceRuntime,
)
m = load_pipeline_from_settings(hf_settings, model_settings)

assert m.model.device == expected


@pytest.mark.parametrize(
"pretrained_model, task, input_batch_size, expected_batch_size",
[
Expand Down