Skip to content

Commit

Permalink
Rename HF codec to hf (#1268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Gonzalez-Martin committed Jul 4, 2023
1 parent 57e4e78 commit 8fea140
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
10 changes: 10 additions & 0 deletions runtimes/huggingface/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ pip install mlserver mlserver-huggingface
For further information on how to use MLServer with HuggingFace, you can check
out this [worked out example](../../docs/examples/huggingface/README.md).

## Content Types

The HuggingFace runtime will always decode the input request using its own
built-in codec.
Therefore, [content type annotations](../../docs/user-guide/content-type) at
the request level will **be ignored**.
Not that this **doesn't include [input-level content
type](../../docs/user-guide/content-type#Codecs) annotations**, which will be
respected as usual.

## Settings

The HuggingFace runtime exposes a couple extra parameters which can be used to
Expand Down
4 changes: 2 additions & 2 deletions runtimes/huggingface/mlserver_huggingface/codecs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MultiInputRequestCodec(RequestCodec):

DefaultCodec: Type["InputCodecTy"] = StringCodec
InputCodecsWithPriority: List[Type[InputCodecTy]] = []
ContentType = StringCodec.ContentType
ContentType = ""

@classmethod
def _find_encode_codecs(
Expand Down Expand Up @@ -194,5 +194,5 @@ class HuggingfaceRequestCodec(MultiInputRequestCodec):
NumpyListCodec,
RawCodec,
]
ContentType = StringCodec.ContentType
ContentType = "hf"
DefaultCodec = StringCodec
2 changes: 1 addition & 1 deletion runtimes/huggingface/mlserver_huggingface/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def load(self) -> bool:

async def predict(self, payload: InferenceRequest) -> InferenceResponse:
# TODO: convert and validate?
kwargs = self.decode_request(payload, default_codec=HuggingfaceRequestCodec)
kwargs = HuggingfaceRequestCodec.decode_request(payload)
args = kwargs.pop("args", [])

array_inputs = kwargs.pop("array_inputs", [])
Expand Down
24 changes: 12 additions & 12 deletions runtimes/huggingface/tests/test_codecs/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{"foo": ["bar1", "bar2"], "foo2": ["var1"]},
False,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="foo",
Expand All @@ -49,7 +49,7 @@
{"foo": ["bar1", "bar2"], "foo2": ["var1"]},
True,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="foo",
Expand Down Expand Up @@ -77,7 +77,7 @@
},
False,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="images",
Expand All @@ -98,7 +98,7 @@
},
True,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="images",
Expand Down Expand Up @@ -128,7 +128,7 @@
},
True,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="conversations",
Expand Down Expand Up @@ -158,7 +158,7 @@
},
False,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="conversations",
Expand All @@ -182,7 +182,7 @@
},
False,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="singlejson",
Expand All @@ -207,7 +207,7 @@
},
True,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="singlejson",
Expand Down Expand Up @@ -241,7 +241,7 @@
},
True,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="jsonlist",
Expand Down Expand Up @@ -277,7 +277,7 @@
},
False,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="jsonlist",
Expand All @@ -299,7 +299,7 @@
{"nplist": [np.int8([[2, 2], [2, 2]]), np.float64([[2, 2], [2, 2]])]},
False,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="nplist",
Expand All @@ -319,7 +319,7 @@
},
False,
InferenceRequest(
parameters=Parameters(content_type="str"),
parameters=Parameters(content_type="hf"),
inputs=[
RequestInput(
name="raw_int",
Expand Down

0 comments on commit 8fea140

Please sign in to comment.