Skip to content

Commit 8fea140

Browse files
author
Adrian Gonzalez-Martin
committed
Rename HF codec to hf (#1268)
1 parent 57e4e78 commit 8fea140

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

runtimes/huggingface/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ pip install mlserver mlserver-huggingface
1313
For further information on how to use MLServer with HuggingFace, you can check
1414
out this [worked out example](../../docs/examples/huggingface/README.md).
1515

16+
## Content Types
17+
18+
The HuggingFace runtime will always decode the input request using its own
19+
built-in codec.
20+
Therefore, [content type annotations](../../docs/user-guide/content-type) at
21+
the request level will **be ignored**.
22+
Not that this **doesn't include [input-level content
23+
type](../../docs/user-guide/content-type#Codecs) annotations**, which will be
24+
respected as usual.
25+
1626
## Settings
1727

1828
The HuggingFace runtime exposes a couple extra parameters which can be used to

runtimes/huggingface/mlserver_huggingface/codecs/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MultiInputRequestCodec(RequestCodec):
4444

4545
DefaultCodec: Type["InputCodecTy"] = StringCodec
4646
InputCodecsWithPriority: List[Type[InputCodecTy]] = []
47-
ContentType = StringCodec.ContentType
47+
ContentType = ""
4848

4949
@classmethod
5050
def _find_encode_codecs(
@@ -194,5 +194,5 @@ class HuggingfaceRequestCodec(MultiInputRequestCodec):
194194
NumpyListCodec,
195195
RawCodec,
196196
]
197-
ContentType = StringCodec.ContentType
197+
ContentType = "hf"
198198
DefaultCodec = StringCodec

runtimes/huggingface/mlserver_huggingface/runtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async def load(self) -> bool:
3838

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

4444
array_inputs = kwargs.pop("array_inputs", [])

runtimes/huggingface/tests/test_codecs/test_base.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{"foo": ["bar1", "bar2"], "foo2": ["var1"]},
2727
False,
2828
InferenceRequest(
29-
parameters=Parameters(content_type="str"),
29+
parameters=Parameters(content_type="hf"),
3030
inputs=[
3131
RequestInput(
3232
name="foo",
@@ -49,7 +49,7 @@
4949
{"foo": ["bar1", "bar2"], "foo2": ["var1"]},
5050
True,
5151
InferenceRequest(
52-
parameters=Parameters(content_type="str"),
52+
parameters=Parameters(content_type="hf"),
5353
inputs=[
5454
RequestInput(
5555
name="foo",
@@ -77,7 +77,7 @@
7777
},
7878
False,
7979
InferenceRequest(
80-
parameters=Parameters(content_type="str"),
80+
parameters=Parameters(content_type="hf"),
8181
inputs=[
8282
RequestInput(
8383
name="images",
@@ -98,7 +98,7 @@
9898
},
9999
True,
100100
InferenceRequest(
101-
parameters=Parameters(content_type="str"),
101+
parameters=Parameters(content_type="hf"),
102102
inputs=[
103103
RequestInput(
104104
name="images",
@@ -128,7 +128,7 @@
128128
},
129129
True,
130130
InferenceRequest(
131-
parameters=Parameters(content_type="str"),
131+
parameters=Parameters(content_type="hf"),
132132
inputs=[
133133
RequestInput(
134134
name="conversations",
@@ -158,7 +158,7 @@
158158
},
159159
False,
160160
InferenceRequest(
161-
parameters=Parameters(content_type="str"),
161+
parameters=Parameters(content_type="hf"),
162162
inputs=[
163163
RequestInput(
164164
name="conversations",
@@ -182,7 +182,7 @@
182182
},
183183
False,
184184
InferenceRequest(
185-
parameters=Parameters(content_type="str"),
185+
parameters=Parameters(content_type="hf"),
186186
inputs=[
187187
RequestInput(
188188
name="singlejson",
@@ -207,7 +207,7 @@
207207
},
208208
True,
209209
InferenceRequest(
210-
parameters=Parameters(content_type="str"),
210+
parameters=Parameters(content_type="hf"),
211211
inputs=[
212212
RequestInput(
213213
name="singlejson",
@@ -241,7 +241,7 @@
241241
},
242242
True,
243243
InferenceRequest(
244-
parameters=Parameters(content_type="str"),
244+
parameters=Parameters(content_type="hf"),
245245
inputs=[
246246
RequestInput(
247247
name="jsonlist",
@@ -277,7 +277,7 @@
277277
},
278278
False,
279279
InferenceRequest(
280-
parameters=Parameters(content_type="str"),
280+
parameters=Parameters(content_type="hf"),
281281
inputs=[
282282
RequestInput(
283283
name="jsonlist",
@@ -299,7 +299,7 @@
299299
{"nplist": [np.int8([[2, 2], [2, 2]]), np.float64([[2, 2], [2, 2]])]},
300300
False,
301301
InferenceRequest(
302-
parameters=Parameters(content_type="str"),
302+
parameters=Parameters(content_type="hf"),
303303
inputs=[
304304
RequestInput(
305305
name="nplist",
@@ -319,7 +319,7 @@
319319
},
320320
False,
321321
InferenceRequest(
322-
parameters=Parameters(content_type="str"),
322+
parameters=Parameters(content_type="hf"),
323323
inputs=[
324324
RequestInput(
325325
name="raw_int",

0 commit comments

Comments
 (0)