Skip to content

Commit 56ffe40

Browse files
authored
[inference] Kill the ability to override a model's task (#1199)
#### Excerpt from [internal convo](https://huggingface.slack.com/archives/C021329G2LT/p1739370292210139): I was wondering, do you know by any chance if, in the old hf-inference-api, the ability to override the pipeline when calling the API between a feature-extraction and a sentence-similarity model, is still used? I am thinking to kill this feature from the client libraries (it's simpler to always assume 1 model === 1 task) and i figured you might know if we still use this anywhere
1 parent a32260f commit 56ffe40

File tree

5 files changed

+3
-121
lines changed

5 files changed

+3
-121
lines changed

packages/inference/src/lib/makeRequestOptions.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ export async function makeRequestOptions(
2828
stream?: boolean;
2929
},
3030
options?: Options & {
31-
/** When a model can be used for multiple tasks, and we want to run a non-default task */
32-
forceTask?: string | InferenceTask;
3331
/** To load default model if needed */
3432
taskHint?: InferenceTask;
3533
chatCompletion?: boolean;
@@ -39,14 +37,11 @@ export async function makeRequestOptions(
3937
let otherArgs = remainingArgs;
4038
const provider = maybeProvider ?? "hf-inference";
4139

42-
const { forceTask, includeCredentials, taskHint, chatCompletion } = options ?? {};
40+
const { includeCredentials, taskHint, chatCompletion } = options ?? {};
4341

4442
if (endpointUrl && provider !== "hf-inference") {
4543
throw new Error(`Cannot use endpointUrl with a third-party provider.`);
4644
}
47-
if (forceTask && provider !== "hf-inference") {
48-
throw new Error(`Cannot use forceTask with a third-party provider.`);
49-
}
5045
if (maybeModel && isUrl(maybeModel)) {
5146
throw new Error(`Model URLs are no longer supported. Use endpointUrl instead.`);
5247
}
@@ -77,7 +72,6 @@ export async function makeRequestOptions(
7772
: makeUrl({
7873
authMethod,
7974
chatCompletion: chatCompletion ?? false,
80-
forceTask,
8175
model,
8276
provider: provider ?? "hf-inference",
8377
taskHint,
@@ -146,7 +140,6 @@ function makeUrl(params: {
146140
model: string;
147141
provider: InferenceProvider;
148142
taskHint: InferenceTask | undefined;
149-
forceTask?: string | InferenceTask;
150143
}): string {
151144
if (params.authMethod === "none" && params.provider !== "hf-inference") {
152145
throw new Error("Authentication is required when requesting a third-party provider. Please provide accessToken");
@@ -224,13 +217,10 @@ function makeUrl(params: {
224217
}
225218
default: {
226219
const baseUrl = HF_HUB_INFERENCE_PROXY_TEMPLATE.replaceAll("{{PROVIDER}}", "hf-inference");
227-
const url = params.forceTask
228-
? `${baseUrl}/pipeline/${params.forceTask}/${params.model}`
229-
: `${baseUrl}/models/${params.model}`;
230220
if (params.taskHint === "text-generation" && params.chatCompletion) {
231-
return url + `/v1/chat/completions`;
221+
return `${baseUrl}/models/${params.model}/v1/chat/completions`;
232222
}
233-
return url;
223+
return `${baseUrl}/models/${params.model}`;
234224
}
235225
}
236226
}

packages/inference/src/tasks/nlp/featureExtraction.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { InferenceOutputError } from "../../lib/InferenceOutputError";
2-
import { getDefaultTask } from "../../lib/getDefaultTask";
32
import type { BaseArgs, Options } from "../../types";
43
import { request } from "../custom/request";
54

@@ -25,12 +24,9 @@ export async function featureExtraction(
2524
args: FeatureExtractionArgs,
2625
options?: Options
2726
): Promise<FeatureExtractionOutput> {
28-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : undefined;
29-
3027
const res = await request<FeatureExtractionOutput>(args, {
3128
...options,
3229
taskHint: "feature-extraction",
33-
...(defaultTask === "sentence-similarity" && { forceTask: "feature-extraction" }),
3430
});
3531
let isValidOutput = true;
3632

packages/inference/src/tasks/nlp/sentenceSimilarity.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { SentenceSimilarityInput, SentenceSimilarityOutput } from "@huggingface/tasks";
22
import { InferenceOutputError } from "../../lib/InferenceOutputError";
3-
import { getDefaultTask } from "../../lib/getDefaultTask";
43
import type { BaseArgs, Options } from "../../types";
54
import { request } from "../custom/request";
65
import { omit } from "../../utils/omit";
@@ -14,11 +13,9 @@ export async function sentenceSimilarity(
1413
args: SentenceSimilarityArgs,
1514
options?: Options
1615
): Promise<SentenceSimilarityOutput> {
17-
const defaultTask = args.model ? await getDefaultTask(args.model, args.accessToken, options) : undefined;
1816
const res = await request<SentenceSimilarityOutput>(prepareInput(args), {
1917
...options,
2018
taskHint: "sentence-similarity",
21-
...(defaultTask === "feature-extraction" && { forceTask: "sentence-similarity" }),
2219
});
2320

2421
const isValidOutput = Array.isArray(res) && res.every((x) => typeof x === "number");

packages/inference/test/HfInference.spec.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,6 @@ describe.concurrent("HfInference", () => {
351351
});
352352
expect(response).toEqual(expect.arrayContaining([expect.any(Number)]));
353353
});
354-
it("FeatureExtraction - same model as sentence similarity", async () => {
355-
const response = await hf.featureExtraction({
356-
model: "sentence-transformers/paraphrase-xlm-r-multilingual-v1",
357-
inputs: "That is a happy person",
358-
});
359-
360-
expect(response.length).toBeGreaterThan(10);
361-
expect(response).toEqual(expect.arrayContaining([expect.any(Number)]));
362-
});
363354
it("FeatureExtraction - facebook/bart-base", async () => {
364355
const response = await hf.featureExtraction({
365356
model: "facebook/bart-base",

0 commit comments

Comments
 (0)