Skip to content

Commit 75b0d15

Browse files
committed
docs: shorter model URI
1 parent 507d804 commit 75b0d15

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

docs/cli/pull.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ If a file already exists and its size matches the expected size, it will not be
2020

2121
The supported URI schemes are:
2222
- **HTTP:** `https://`, `http://`
23+
- **Hugging Face:** `hf:<user>/<model>:<quant>` (`#<quant>` is optional, [but recommended](../guide/downloading-models.md#hf-scheme-specify-quant))
2324
- **Hugging Face:** `hf:<user>/<model>/<file-path>#<branch>` (`#<branch>` is optional)
2425

2526
Learn more about using model URIs in the [Downloading Models guide](../guide/downloading-models.md#model-uris).

docs/guide/downloading-models.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,19 @@ You can reference models using a URI instead of their full download URL when usi
7575

7676
When downloading a model from a URI, the model files will be prefixed with a corresponding adaptation of the URI.
7777

78-
To reference a model from Hugging Face, you can use the scheme
79-
<br/>
80-
`hf:<user>/<model>/<file-path>#<branch>` (`#<branch>` is optional).
78+
To reference a model from Hugging Face, you can use one of these schemes:
79+
* `hf:<user>/<model>:<quant>` (`#<quant>` is optional, [but recommended](#hf-scheme-specify-quant))
80+
* `hf:<user>/<model>/<file-path>#<branch>` (`#<branch>` is optional)
8181

82-
Here's an example usage of the Hugging Face URI scheme:
82+
Here are example usages of the Hugging Face URI scheme:
83+
::: code-group
84+
```[With quant]
85+
hf:mradermacher/Meta-Llama-3.1-8B-Instruct-GGUF:Q4_K_M
8386
```
87+
```[Specific file]
8488
hf:mradermacher/Meta-Llama-3.1-8B-Instruct-GGUF/Meta-Llama-3.1-8B-Instruct.Q4_K_M.gguf
8589
```
90+
:::
8691

8792
When using a URI to reference a model,
8893
it's recommended [to add it to your `package.json` file](#cli) to ensure it's downloaded when running `npm install`,
@@ -98,7 +103,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
98103
const modelsDirectory = path.join(__dirname, "models");
99104

100105
const modelPath = await resolveModelFile(
101-
"hf:user/model/model-file.gguf",
106+
"hf:user/model:quant",
102107
modelsDirectory
103108
);
104109

@@ -114,6 +119,13 @@ When a file is being downloaded, the download progress is shown in the console b
114119
Set the [`cli`](../api/type-aliases/ResolveModelFileOptions#cli) option to `false` to disable this behavior.
115120
:::
116121

122+
::: tip TIP {#hf-scheme-specify-quant}
123+
When using the `hf:<user>/<model>:<quant>` scheme, always specify the quantization level in the URI (`:<quant>`).
124+
<br/>
125+
Doing this allows the resolver to resolve to a local model file without checking the model metadata on Hugging Face first,
126+
so it will be resolved offline and faster.
127+
:::
128+
117129
## Downloading Gated Models From Hugging Face {#hf-token}
118130
Some models on Hugging Face are "gated", meaning they require a manual consent from you before you can download them.
119131

src/cli/utils/resolveModelRecommendationFileOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import {resolveModelDestination} from "../../utils/resolveModelDestination.js";
33
export type ModelURI = `${
44
`http://${string}/${string}` |
55
`https://${string}/${string}` |
6+
`hf:${string}/${string}:${string}` |
7+
`huggingface:${string}/${string}:${string}` |
8+
`hf.co/${string}/${string}:${string}` |
9+
`huggingface.co/${string}/${string}:${string}` |
610
`hf:${string}/${string}/${string}` |
711
`huggingface:${string}/${string}/${string}`
812
}${

src/utils/createModelDownloader.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type ModelDownloaderOptions = ({
1717
*
1818
* The supported URI schemes are:
1919
* - **HTTP:** `https://`, `http://`
20+
* - **Hugging Face:** `hf:<user>/<model>:<quant>` (`#<quant>` is optional, but recommended)
2021
* - **Hugging Face:** `hf:<user>/<model>/<file-path>#<branch>` (`#<branch>` is optional)
2122
*/
2223
modelUri: string
@@ -83,6 +84,7 @@ export type ModelDownloaderOptions = ({
8384
*
8485
* The supported URI schemes are:
8586
* - **HTTP:** `https://`, `http://`
87+
* - **Hugging Face:** `hf:<user>/<model>:<quant>` (`#<quant>` is optional, but recommended)
8688
* - **Hugging Face:** `hf:<user>/<model>/<file-path>#<branch>` (`#<branch>` is optional)
8789
* @example
8890
* ```typescript
@@ -112,7 +114,7 @@ export type ModelDownloaderOptions = ({
112114
* const __dirname = path.dirname(fileURLToPath(import.meta.url));
113115
*
114116
* const downloader = await createModelDownloader({
115-
* modelUri: "hf:user/model/model-file.gguf",
117+
* modelUri: "hf:user/model:quant",
116118
* dirPath: path.join(__dirname, "models")
117119
* });
118120
* const modelPath = await downloader.download();
@@ -153,7 +155,11 @@ export function createModelDownloader(options: ModelDownloaderOptions) {
153155
* dirPath: path.join(__dirname, "models")
154156
* }),
155157
* createModelDownloader({
156-
* modelUri: "hf:user/model/model2.gguf",
158+
* modelUri: "hf:user/model2:quant",
159+
* dirPath: path.join(__dirname, "models")
160+
* }),
161+
* createModelDownloader({
162+
* modelUri: "hf:user/model/model3.gguf",
157163
* dirPath: path.join(__dirname, "models")
158164
* })
159165
* ];
@@ -162,7 +168,8 @@ export function createModelDownloader(options: ModelDownloaderOptions) {
162168
* });
163169
* const [
164170
* model1Path,
165-
* model2Path
171+
* model2Path,
172+
* model3Path
166173
* ] = await combinedDownloader.download();
167174
*
168175
* const llama = await getLlama();
@@ -172,6 +179,9 @@ export function createModelDownloader(options: ModelDownloaderOptions) {
172179
* const model2 = await llama.loadModel({
173180
* modelPath: model2Path!
174181
* });
182+
* const model3 = await llama.loadModel({
183+
* modelPath: model3Path!
184+
* });
175185
* ```
176186
*/
177187
export async function combineModelDownloaders(

src/utils/resolveModelFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export type ResolveModelFileOptions = {
111111
*
112112
* // resolve a model from Hugging Face to the models directory
113113
* const modelPath = await resolveModelFile(
114-
* "hf:user/model/model-file.gguf",
114+
* "hf:user/model:quant",
115115
* path.join(__dirname, "models")
116116
* );
117117
*

0 commit comments

Comments
 (0)