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

draft: add hyperbolic support #1191

Merged
merged 21 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 6 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ jobs:
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_FAL_KEY: dummy
HF_FIREWORKS_KEY: dummy
HF_HYPERBOLIC_KEY: dummy
HF_NEBIUS_KEY: dummy
HF_REPLICATE_KEY: dummy
HF_SAMBANOVA_KEY: dummy
HF_TOGETHER_KEY: dummy
HF_FIREWORKS_KEY: dummy

browser:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down Expand Up @@ -84,12 +84,12 @@ jobs:
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_FAL_KEY: dummy
HF_FIREWORKS_KEY: dummy
HF_HYPERBOLIC_KEY: dummy
HF_NEBIUS_KEY: dummy
HF_REPLICATE_KEY: dummy
HF_SAMBANOVA_KEY: dummy
HF_TOGETHER_KEY: dummy
HF_FIREWORKS_KEY: dummy

e2e:
runs-on: ubuntu-latest
timeout-minutes: 10
Expand Down Expand Up @@ -153,8 +153,9 @@ jobs:
NPM_CONFIG_REGISTRY: http://localhost:4874/
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_FAL_KEY: dummy
HF_FIREWORKS_KEY: dummy
HF_HYPERBOLIC_KEY: dummy
HF_NEBIUS_KEY: dummy
HF_REPLICATE_KEY: dummy
HF_SAMBANOVA_KEY: dummy
HF_TOGETHER_KEY: dummy
HF_FIREWORKS_KEY: dummy
2 changes: 2 additions & 0 deletions packages/inference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ You can send inference requests to third-party providers with the inference clie
Currently, we support the following providers:
- [Fal.ai](https://fal.ai)
- [Fireworks AI](https://fireworks.ai)
- [Hyperbolic](https://hyperbolic.xyz)
- [Nebius](https://studio.nebius.ai)
- [Replicate](https://replicate.com)
- [Sambanova](https://sambanova.ai)
Expand All @@ -72,6 +73,7 @@ When authenticated with a third-party provider key, the request is made directly
Only a subset of models are supported when requesting third-party providers. You can check the list of supported models per pipeline tasks here:
- [Fal.ai supported models](https://huggingface.co/api/partners/fal-ai/models)
- [Fireworks AI supported models](https://huggingface.co/api/partners/fireworks-ai/models)
- [Hyperbolic supported models](https://huggingface.co/api/partners/hyperbolic/models)
- [Nebius supported models](https://huggingface.co/api/partners/nebius/models)
- [Replicate supported models](https://huggingface.co/api/partners/replicate/models)
- [Sambanova supported models](https://huggingface.co/api/partners/sambanova/models)
Expand Down
7 changes: 7 additions & 0 deletions packages/inference/src/lib/makeRequestOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { REPLICATE_API_BASE_URL } from "../providers/replicate";
import { SAMBANOVA_API_BASE_URL } from "../providers/sambanova";
import { TOGETHER_API_BASE_URL } from "../providers/together";
import { FIREWORKS_AI_API_BASE_URL } from "../providers/fireworks-ai";
import { HYPERBOLIC_API_BASE_URL } from "../providers/hyperbolic";
import type { InferenceProvider } from "../types";
import type { InferenceTask, Options, RequestArgs } from "../types";
import { isUrl } from "./isUrl";
Expand Down Expand Up @@ -235,6 +236,12 @@ function makeUrl(params: {
}
return baseUrl;
}
case "hyperbolic": {
const baseUrl = shouldProxy
? HF_HUB_INFERENCE_PROXY_TEMPLATE.replace("{{PROVIDER}}", params.provider)
: HYPERBOLIC_API_BASE_URL;
return `${baseUrl}/v1/chat/completions`;
}
default: {
const baseUrl = HF_HUB_INFERENCE_PROXY_TEMPLATE.replaceAll("{{PROVIDER}}", "hf-inference");
const url = params.forceTask
Expand Down
1 change: 1 addition & 0 deletions packages/inference/src/providers/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const HARDCODED_MODEL_ID_MAPPING: Record<InferenceProvider, Record<ModelI
"fal-ai": {},
"fireworks-ai": {},
"hf-inference": {},
hyperbolic: {},
nebius: {},
replicate: {},
sambanova: {},
Expand Down
18 changes: 18 additions & 0 deletions packages/inference/src/providers/hyperbolic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const HYPERBOLIC_API_BASE_URL = "https://api.hyperbolic.xyz";

/**
* See the registered mapping of HF model ID => Hyperbolic model ID here:
*
* https://huggingface.co/api/partners/hyperbolic/models
*
* This is a publicly available mapping.
*
* If you want to try to run inference for a new model locally before it's registered on huggingface.co,
* you can add it to the dictionary "HARDCODED_MODEL_ID_MAPPING" in consts.ts, for dev purposes.
*
* - If you work at Hyperbolic and want to update this mapping, please use the model mapping API we provide on huggingface.co
* - If you're a community member and want to add a new supported HF model to Hyperbolic, please open an issue on the present repo
* and we will tag Hyperbolic team members.
*
* Thanks!
*/
4 changes: 3 additions & 1 deletion packages/inference/src/tasks/custom/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ export async function request<T>(
}
if (output.error || output.detail) {
throw new Error(JSON.stringify(output.error ?? output.detail));
} else if (typeof output === "object") {
throw new Error(JSON.stringify(output));
} else {
throw new Error(output);
throw new Error(String(output));
}
}
const message = contentType?.startsWith("text/plain;") ? await response.text() : undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/inference/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type InferenceTask = Exclude<PipelineType, "other">;
export const INFERENCE_PROVIDERS = [
"fal-ai",
"fireworks-ai",
"hyperbolic",
"nebius",
"hf-inference",
"replicate",
Expand Down
72 changes: 72 additions & 0 deletions packages/inference/test/HfInference.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,4 +1175,76 @@ describe.concurrent("HfInference", () => {
},
TIMEOUT
);

describe.concurrent(
"Hyperbolic",
() => {
const client = new HfInference(env.HF_HYPERBOLIC_KEY);

HARDCODED_MODEL_ID_MAPPING.hyperbolic = {
"meta-llama/Llama-3.2-3B-Instruct": "meta-llama/Llama-3.2-3B-Instruct",
"meta-llama/Llama-3.3-70B-Instruct": "meta-llama/Llama-3.3-70B-Instruct",
"stabilityai/stable-diffusion-2": "stabilityai/stable-diffusion-2",
"meta-llama/Llama-3.1-405B-BASE-FP8": "meta-llama/Llama-3.1-405B-BASE-FP8",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the keys should be HF model ids (it's not the case for the last one at least)

};

it("chatCompletion - hyperbolic", async () => {
const res = await client.chatCompletion({
model: "meta-llama/Llama-3.2-3B-Instruct",
provider: "hyperbolic",
messages: [{ role: "user", content: "Complete this sentence with words, one plus one is equal " }],
temperature: 0.1,
});

expect(res).toBeDefined();
expect(res.choices).toBeDefined();
expect(res.choices?.length).toBeGreaterThan(0);

if (res.choices && res.choices.length > 0) {
const completion = res.choices[0].message?.content;
expect(completion).toBeDefined();
expect(typeof completion).toBe("string");
expect(completion).toContain("two");
}
});

it("chatCompletion stream", async () => {
const stream = client.chatCompletionStream({
model: "meta-llama/Llama-3.3-70B-Instruct",
provider: "hyperbolic",
messages: [{ role: "user", content: "Complete the equation 1 + 1 = , just the answer" }],
}) as AsyncGenerator<ChatCompletionStreamOutput>;
let out = "";
for await (const chunk of stream) {
if (chunk.choices && chunk.choices.length > 0) {
out += chunk.choices[0].delta.content;
}
}
expect(out).toContain("2");
});

it("textToImage", async () => {
const res = await client.textToImage({
model: "stabilityai/stable-diffusion-2",
provider: "hyperbolic",
inputs: "award winning high resolution photo of a giant tortoise",
});
expect(res).toBeInstanceOf(Blob);
});

it("textGeneration", async () => {
const res = await client.textGeneration({
model: "meta-llama/Llama-3.1-405B-BASE-FP8",
provider: "hyperbolic",
inputs: "Paris is",
parameters: {
temperature: 0,
max_tokens: 10,
},
});
expect(res).toMatchObject({ generated_text: " city of love" });
});
},
TIMEOUT
);
});
Loading