Buckets:

rtrm's picture
|
download
raw
25.9 kB
# utils/hub
Utility functions to interact with the Hugging Face Hub (https://huggingface.co/models)
* [utils/hub](#module_utils/hub)
* _static_
* [`.getFile(urlOrPath)`](#module_utils/hub.getFile) ⇒ <code>Promise.&lt;(FileResponse|Response)&gt;</code>
* [`.getModelFile(path_or_repo_id, filename, [fatal], [options], [return_path])`](#module_utils/hub.getModelFile) ⇒ <code>Promise.&lt;(string|Uint8Array)&gt;</code>
* [`~cacheKey`](#module_utils/hub.getModelFile..cacheKey) : <code>string</code>
* [`~response`](#module_utils/hub.getModelFile..response) : <code>Response</code> | <code>FileResponse</code> | <code>undefined</code>
* [`~buffer`](#module_utils/hub.getModelFile..buffer) : <code>Uint8Array</code>
* [`.getModelText(modelPath, fileName, [fatal], [options])`](#module_utils/hub.getModelText) ⇒ <code>Promise.&lt;(string|null)&gt;</code>
* [`.getModelJSON(modelPath, fileName, [fatal], [options])`](#module_utils/hub.getModelJSON) ⇒ <code>Promise.&lt;Object&gt;</code>
* _inner_
* [~FileResponse](#module_utils/hub..FileResponse)
* [`new FileResponse(filePath)`](#new_module_utils/hub..FileResponse_new)
* [`.updateContentType()`](#module_utils/hub..FileResponse+updateContentType) ⇒ <code>void</code>
* [`.clone()`](#module_utils/hub..FileResponse+clone) ⇒ <code>FileResponse</code>
* [`.arrayBuffer()`](#module_utils/hub..FileResponse+arrayBuffer) ⇒ <code>Promise.&lt;ArrayBuffer&gt;</code>
* [`.blob()`](#module_utils/hub..FileResponse+blob) ⇒ <code>Promise.&lt;Blob&gt;</code>
* [`.text()`](#module_utils/hub..FileResponse+text) ⇒ <code>Promise.&lt;string&gt;</code>
* [`.json()`](#module_utils/hub..FileResponse+json) ⇒ <code>Promise.&lt;Object&gt;</code>
* [~FileCache](#module_utils/hub..FileCache)
* [`new FileCache(path)`](#new_module_utils/hub..FileCache_new)
* [`.match(request)`](#module_utils/hub..FileCache+match) ⇒ <code>Promise.&lt;(FileResponse|undefined)&gt;</code>
* [`.put(request, response, [progress_callback])`](#module_utils/hub..FileCache+put) ⇒ <code>Promise.&lt;void&gt;</code>
* [`~CONTENT_TYPE_MAP`](#module_utils/hub..CONTENT_TYPE_MAP)
* [`~isValidUrl(string, [protocols], [validHosts])`](#module_utils/hub..isValidUrl) ⇒ <code>boolean</code>
* [`~isValidHfModelId(string)`](#module_utils/hub..isValidHfModelId) ⇒ <code>boolean</code>
* [`~handleError(status, remoteURL, fatal)`](#module_utils/hub..handleError) ⇒ <code>null</code>
* [`~tryCache(cache, ...names)`](#module_utils/hub..tryCache) ⇒ <code>Promise.&lt;(FileResponse|Response|undefined)&gt;</code>
* [`~readResponse(response, progress_callback)`](#module_utils/hub..readResponse) ⇒ <code>Promise.&lt;Uint8Array&gt;</code>
* [`~pathJoin(...parts)`](#module_utils/hub..pathJoin) ⇒ <code>string</code>
* [`~ExternalData`](#module_utils/hub..ExternalData) : <code>boolean</code> | <code>number</code>
* [`~PretrainedOptions`](#module_utils/hub..PretrainedOptions) : <code>Object</code>
* [`~ModelSpecificPretrainedOptions`](#module_utils/hub..ModelSpecificPretrainedOptions) : <code>Object</code>
* [`~PretrainedModelOptions`](#module_utils/hub..PretrainedModelOptions) : <code>*</code>
* * *
<a id="module_utils/hub.getFile" class="group"></a>
## `utils/hub.getFile(urlOrPath)` ⇒ <code>Promise.&lt;(FileResponse|Response)&gt;</code>
Helper function to get a file, using either the Fetch API or FileSystem API.
**Kind**: static method of [<code>utils/hub</code>](#module_utils/hub)
**Returns**: <code>Promise.&lt;(FileResponse|Response)&gt;</code> - A promise that resolves to a FileResponse object (if the file is retrieved using the FileSystem API), or a Response object (if the file is retrieved using the Fetch API).
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>urlOrPath</td><td><code>URL</code> | <code>string</code></td><td><p>The URL/path of the file to get.</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub.getModelFile" class="group"></a>
## `utils/hub.getModelFile(path_or_repo_id, filename, [fatal], [options], [return_path])` ⇒ <code>Promise.&lt;(string|Uint8Array)&gt;</code>
Retrieves a file from either a remote URL using the Fetch API or from the local file system using the FileSystem API.
If the filesystem is available and `env.useCache = true`, the file will be downloaded and cached.
**Kind**: static method of [<code>utils/hub</code>](#module_utils/hub)
**Returns**: <code>Promise.&lt;(string|Uint8Array)&gt;</code> - A Promise that resolves with the file content as a Uint8Array if `return_path` is false, or the file path as a string if `return_path` is true.
**Throws**:
- Will throw an error if the file is not found and `fatal` is true.
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Default</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>path_or_repo_id</td><td><code>string</code></td><td></td><td><p>This can be either:</p>
<ul>
<li>a string, the <em>model id</em> of a model repo on huggingface.co.</li>
<li>a path to a <em>directory</em> potentially containing the file.</li>
</ul>
</td>
</tr><tr>
<td>filename</td><td><code>string</code></td><td></td><td><p>The name of the file to locate in <code>path_or_repo</code>.</p>
</td>
</tr><tr>
<td>[fatal]</td><td><code>boolean</code></td><td><code>true</code></td><td><p>Whether to throw an error if the file is not found.</p>
</td>
</tr><tr>
<td>[options]</td><td><code>PretrainedOptions</code></td><td></td><td><p>An object containing optional parameters.</p>
</td>
</tr><tr>
<td>[return_path]</td><td><code>boolean</code></td><td><code>false</code></td><td><p>Whether to return the path of the file instead of the file content.</p>
</td>
</tr> </tbody>
</table>
* [`.getModelFile(path_or_repo_id, filename, [fatal], [options], [return_path])`](#module_utils/hub.getModelFile) ⇒ <code>Promise.&lt;(string|Uint8Array)&gt;</code>
* [`~cacheKey`](#module_utils/hub.getModelFile..cacheKey) : <code>string</code>
* [`~response`](#module_utils/hub.getModelFile..response) : <code>Response</code> | <code>FileResponse</code> | <code>undefined</code>
* [`~buffer`](#module_utils/hub.getModelFile..buffer) : <code>Uint8Array</code>
* * *
<a id="module_utils/hub.getModelFile..cacheKey" class="group"></a>
### `getModelFile~cacheKey` : <code>string</code>
**Kind**: inner property of [<code>getModelFile</code>](#module_utils/hub.getModelFile)
* * *
<a id="module_utils/hub.getModelFile..response" class="group"></a>
### `getModelFile~response` : <code>Response</code> | <code>FileResponse</code> | <code>undefined</code>
**Kind**: inner property of [<code>getModelFile</code>](#module_utils/hub.getModelFile)
* * *
<a id="module_utils/hub.getModelFile..buffer" class="group"></a>
### `getModelFile~buffer` : <code>Uint8Array</code>
**Kind**: inner property of [<code>getModelFile</code>](#module_utils/hub.getModelFile)
* * *
<a id="module_utils/hub.getModelText" class="group"></a>
## `utils/hub.getModelText(modelPath, fileName, [fatal], [options])` ⇒ <code>Promise.&lt;(string|null)&gt;</code>
Fetches a text file from a given path and file name.
**Kind**: static method of [<code>utils/hub</code>](#module_utils/hub)
**Returns**: <code>Promise.&lt;(string|null)&gt;</code> - The text content of the file.
**Throws**:
- Will throw an error if the file is not found and `fatal` is true.
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Default</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>modelPath</td><td><code>string</code></td><td></td><td><p>The path to the directory containing the file.</p>
</td>
</tr><tr>
<td>fileName</td><td><code>string</code></td><td></td><td><p>The name of the file to fetch.</p>
</td>
</tr><tr>
<td>[fatal]</td><td><code>boolean</code></td><td><code>true</code></td><td><p>Whether to throw an error if the file is not found.</p>
</td>
</tr><tr>
<td>[options]</td><td><code>PretrainedOptions</code></td><td></td><td><p>An object containing optional parameters.</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub.getModelJSON" class="group"></a>
## `utils/hub.getModelJSON(modelPath, fileName, [fatal], [options])` ⇒ <code>Promise.&lt;Object&gt;</code>
Fetches a JSON file from a given path and file name.
**Kind**: static method of [<code>utils/hub</code>](#module_utils/hub)
**Returns**: <code>Promise.&lt;Object&gt;</code> - The JSON data parsed into a JavaScript object.
**Throws**:
- Will throw an error if the file is not found and `fatal` is true.
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Default</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>modelPath</td><td><code>string</code></td><td></td><td><p>The path to the directory containing the file.</p>
</td>
</tr><tr>
<td>fileName</td><td><code>string</code></td><td></td><td><p>The name of the file to fetch.</p>
</td>
</tr><tr>
<td>[fatal]</td><td><code>boolean</code></td><td><code>true</code></td><td><p>Whether to throw an error if the file is not found.</p>
</td>
</tr><tr>
<td>[options]</td><td><code>PretrainedOptions</code></td><td></td><td><p>An object containing optional parameters.</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..FileResponse" class="group"></a>
## utils/hub~FileResponse
**Kind**: inner class of [<code>utils/hub</code>](#module_utils/hub)
* [~FileResponse](#module_utils/hub..FileResponse)
* [`new FileResponse(filePath)`](#new_module_utils/hub..FileResponse_new)
* [`.updateContentType()`](#module_utils/hub..FileResponse+updateContentType) ⇒ <code>void</code>
* [`.clone()`](#module_utils/hub..FileResponse+clone) ⇒ <code>FileResponse</code>
* [`.arrayBuffer()`](#module_utils/hub..FileResponse+arrayBuffer) ⇒ <code>Promise.&lt;ArrayBuffer&gt;</code>
* [`.blob()`](#module_utils/hub..FileResponse+blob) ⇒ <code>Promise.&lt;Blob&gt;</code>
* [`.text()`](#module_utils/hub..FileResponse+text) ⇒ <code>Promise.&lt;string&gt;</code>
* [`.json()`](#module_utils/hub..FileResponse+json) ⇒ <code>Promise.&lt;Object&gt;</code>
* * *
<a id="new_module_utils/hub..FileResponse_new" class="group"></a>
### `new FileResponse(filePath)`
Creates a new `FileResponse` object.
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>filePath</td><td><code>string</code></td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..FileResponse+updateContentType" class="group"></a>
### `fileResponse.updateContentType()` ⇒ <code>void</code>
Updates the 'content-type' header property of the response based on the extension of
the file specified by the filePath property of the current object.
**Kind**: instance method of [<code>FileResponse</code>](#module_utils/hub..FileResponse)
* * *
<a id="module_utils/hub..FileResponse+clone" class="group"></a>
### `fileResponse.clone()` ⇒ <code>FileResponse</code>
Clone the current FileResponse object.
**Kind**: instance method of [<code>FileResponse</code>](#module_utils/hub..FileResponse)
**Returns**: <code>FileResponse</code> - A new FileResponse object with the same properties as the current object.
* * *
<a id="module_utils/hub..FileResponse+arrayBuffer" class="group"></a>
### `fileResponse.arrayBuffer()` ⇒ <code>Promise.&lt;ArrayBuffer&gt;</code>
Reads the contents of the file specified by the filePath property and returns a Promise that
resolves with an ArrayBuffer containing the file's contents.
**Kind**: instance method of [<code>FileResponse</code>](#module_utils/hub..FileResponse)
**Returns**: <code>Promise.&lt;ArrayBuffer&gt;</code> - A Promise that resolves with an ArrayBuffer containing the file's contents.
**Throws**:
- <code>Error</code> If the file cannot be read.
* * *
<a id="module_utils/hub..FileResponse+blob" class="group"></a>
### `fileResponse.blob()` ⇒ <code>Promise.&lt;Blob&gt;</code>
Reads the contents of the file specified by the filePath property and returns a Promise that
resolves with a Blob containing the file's contents.
**Kind**: instance method of [<code>FileResponse</code>](#module_utils/hub..FileResponse)
**Returns**: <code>Promise.&lt;Blob&gt;</code> - A Promise that resolves with a Blob containing the file's contents.
**Throws**:
- <code>Error</code> If the file cannot be read.
* * *
<a id="module_utils/hub..FileResponse+text" class="group"></a>
### `fileResponse.text()` ⇒ <code>Promise.&lt;string&gt;</code>
Reads the contents of the file specified by the filePath property and returns a Promise that
resolves with a string containing the file's contents.
**Kind**: instance method of [<code>FileResponse</code>](#module_utils/hub..FileResponse)
**Returns**: <code>Promise.&lt;string&gt;</code> - A Promise that resolves with a string containing the file's contents.
**Throws**:
- <code>Error</code> If the file cannot be read.
* * *
<a id="module_utils/hub..FileResponse+json" class="group"></a>
### `fileResponse.json()` ⇒ <code>Promise.&lt;Object&gt;</code>
Reads the contents of the file specified by the filePath property and returns a Promise that
resolves with a parsed JavaScript object containing the file's contents.
**Kind**: instance method of [<code>FileResponse</code>](#module_utils/hub..FileResponse)
**Returns**: <code>Promise.&lt;Object&gt;</code> - A Promise that resolves with a parsed JavaScript object containing the file's contents.
**Throws**:
- <code>Error</code> If the file cannot be read.
* * *
<a id="module_utils/hub..FileCache" class="group"></a>
## utils/hub~FileCache
**Kind**: inner class of [<code>utils/hub</code>](#module_utils/hub)
* [~FileCache](#module_utils/hub..FileCache)
* [`new FileCache(path)`](#new_module_utils/hub..FileCache_new)
* [`.match(request)`](#module_utils/hub..FileCache+match) ⇒ <code>Promise.&lt;(FileResponse|undefined)&gt;</code>
* [`.put(request, response, [progress_callback])`](#module_utils/hub..FileCache+put) ⇒ <code>Promise.&lt;void&gt;</code>
* * *
<a id="new_module_utils/hub..FileCache_new" class="group"></a>
### `new FileCache(path)`
Instantiate a `FileCache` object.
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>path</td><td><code>string</code></td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..FileCache+match" class="group"></a>
### `fileCache.match(request)` ⇒ <code>Promise.&lt;(FileResponse|undefined)&gt;</code>
Checks whether the given request is in the cache.
**Kind**: instance method of [<code>FileCache</code>](#module_utils/hub..FileCache)
<table>
<thead>
<tr>
<th>Param</th><th>Type</th>
</tr>
</thead>
<tbody>
<tr>
<td>request</td><td><code>string</code></td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..FileCache+put" class="group"></a>
### `fileCache.put(request, response, [progress_callback])` ⇒ <code>Promise.&lt;void&gt;</code>
Adds the given response to the cache.
**Kind**: instance method of [<code>FileCache</code>](#module_utils/hub..FileCache)
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>request</td><td><code>string</code></td><td></td>
</tr><tr>
<td>response</td><td><code>Response</code></td><td></td>
</tr><tr>
<td>[progress_callback]</td><td><code>*</code></td><td><p>Optional.
The function to call with progress updates</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..CONTENT_TYPE_MAP" class="group"></a>
## `utils/hub~CONTENT_TYPE_MAP`
Mapping from file extensions to MIME types.
**Kind**: inner constant of [<code>utils/hub</code>](#module_utils/hub)
* * *
<a id="module_utils/hub..isValidUrl" class="group"></a>
## `utils/hub~isValidUrl(string, [protocols], [validHosts])` ⇒ <code>boolean</code>
Determines whether the given string is a valid URL.
**Kind**: inner method of [<code>utils/hub</code>](#module_utils/hub)
**Returns**: <code>boolean</code> - True if the string is a valid URL, false otherwise.
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Default</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>string</td><td><code>string</code> | <code>URL</code></td><td></td><td><p>The string to test for validity as an URL.</p>
</td>
</tr><tr>
<td>[protocols]</td><td><code>Array.&lt;string&gt;</code></td><td><code></code></td><td><p>A list of valid protocols. If specified, the protocol must be in this list.</p>
</td>
</tr><tr>
<td>[validHosts]</td><td><code>Array.&lt;string&gt;</code></td><td><code></code></td><td><p>A list of valid hostnames. If specified, the URL&#39;s hostname must be in this list.</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..isValidHfModelId" class="group"></a>
## `utils/hub~isValidHfModelId(string)` ⇒ <code>boolean</code>
Tests whether a string is a valid Hugging Face model ID or not.
Adapted from https://github.com/huggingface/huggingface_hub/blob/6378820ebb03f071988a96c7f3268f5bdf8f9449/src/huggingface_hub/utils/_validators.py#L119-L170
**Kind**: inner method of [<code>utils/hub</code>](#module_utils/hub)
**Returns**: <code>boolean</code> - True if the string is a valid model ID, false otherwise.
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>string</td><td><code>string</code></td><td><p>The string to test</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..handleError" class="group"></a>
## `utils/hub~handleError(status, remoteURL, fatal)` ⇒ <code>null</code>
Helper method to handle fatal errors that occur while trying to load a file from the Hugging Face Hub.
**Kind**: inner method of [<code>utils/hub</code>](#module_utils/hub)
**Returns**: <code>null</code> - Returns `null` if `fatal = true`.
**Throws**:
- <code>Error</code> If `fatal = false`.
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>status</td><td><code>number</code></td><td><p>The HTTP status code of the error.</p>
</td>
</tr><tr>
<td>remoteURL</td><td><code>string</code></td><td><p>The URL of the file that could not be loaded.</p>
</td>
</tr><tr>
<td>fatal</td><td><code>boolean</code></td><td><p>Whether to raise an error if the file could not be loaded.</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..tryCache" class="group"></a>
## `utils/hub~tryCache(cache, ...names)` ⇒ <code>Promise.&lt;(FileResponse|Response|undefined)&gt;</code>
**Kind**: inner method of [<code>utils/hub</code>](#module_utils/hub)
**Returns**: <code>Promise.&lt;(FileResponse|Response|undefined)&gt;</code> - The item from the cache, or undefined if not found.
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>cache</td><td><code>FileCache</code> | <code>Cache</code></td><td><p>The cache to search</p>
</td>
</tr><tr>
<td>...names</td><td><code>Array.&lt;string&gt;</code></td><td><p>The names of the item to search for</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..readResponse" class="group"></a>
## `utils/hub~readResponse(response, progress_callback)` ⇒ <code>Promise.&lt;Uint8Array&gt;</code>
Read and track progress when reading a Response object
**Kind**: inner method of [<code>utils/hub</code>](#module_utils/hub)
**Returns**: <code>Promise.&lt;Uint8Array&gt;</code> - A Promise that resolves with the Uint8Array buffer
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>response</td><td><code>Response</code> | <code>FileResponse</code></td><td><p>The Response object to read</p>
</td>
</tr><tr>
<td>progress_callback</td><td><code>*</code></td><td><p>The function to call with progress updates</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..pathJoin" class="group"></a>
## `utils/hub~pathJoin(...parts)` ⇒ <code>string</code>
Joins multiple parts of a path into a single path, while handling leading and trailing slashes.
**Kind**: inner method of [<code>utils/hub</code>](#module_utils/hub)
**Returns**: <code>string</code> - A string representing the joined path.
<table>
<thead>
<tr>
<th>Param</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>...parts</td><td><code>string</code></td><td><p>Multiple parts of a path.</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..ExternalData" class="group"></a>
## `utils/hub~ExternalData` : <code>boolean</code> | <code>number</code>
Whether to load the model using the external data format (used for models >= 2GB in size).
If `true`, the model will be loaded using the external data format.
If a number, this many chunks will be loaded using the external data format (of the form: "model.onnx_data[_{chunk_number}]").
**Kind**: inner typedef of [<code>utils/hub</code>](#module_utils/hub)
* * *
<a id="module_utils/hub..PretrainedOptions" class="group"></a>
## `utils/hub~PretrainedOptions` : <code>Object</code>
Options for loading a pretrained model.
**Kind**: inner typedef of [<code>utils/hub</code>](#module_utils/hub)
**Properties**
<table>
<thead>
<tr>
<th>Name</th><th>Type</th><th>Default</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>[progress_callback]</td><td><code>*</code></td><td><code></code></td><td><p>If specified, this function will be called during model construction, to provide the user with progress updates.</p>
</td>
</tr><tr>
<td>[config]</td><td><code>*</code></td><td><code></code></td><td><p>Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:</p>
<ul>
<li>The model is a model provided by the library (loaded with the <em>model id</em> string of a pretrained model).</li>
<li>The model is loaded by supplying a local directory as <code>pretrained_model_name_or_path</code> and a configuration JSON file named <em>config.json</em> is found in the directory.</li>
</ul>
</td>
</tr><tr>
<td>[cache_dir]</td><td><code>string</code></td><td><code>null</code></td><td><p>Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.</p>
</td>
</tr><tr>
<td>[local_files_only]</td><td><code>boolean</code></td><td><code>false</code></td><td><p>Whether or not to only look at local files (e.g., not try downloading the model).</p>
</td>
</tr><tr>
<td>[revision]</td><td><code>string</code></td><td><code>&quot;&#x27;main&#x27;&quot;</code></td><td><p>The specific model version to use. It can be a branch name, a tag name, or a commit id,
since we use a git-based system for storing models and other artifacts on huggingface.co, so <code>revision</code> can be any identifier allowed by git.
NOTE: This setting is ignored for local requests.</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..ModelSpecificPretrainedOptions" class="group"></a>
## `utils/hub~ModelSpecificPretrainedOptions` : <code>Object</code>
Options for loading a pretrained model.
**Kind**: inner typedef of [<code>utils/hub</code>](#module_utils/hub)
**Properties**
<table>
<thead>
<tr>
<th>Name</th><th>Type</th><th>Default</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>[subfolder]</td><td><code>string</code></td><td><code>&quot;&#x27;onnx&#x27;&quot;</code></td><td><p>In case the relevant files are located inside a subfolder of the model repo on huggingface.co,
you can specify the folder name here.</p>
</td>
</tr><tr>
<td>[model_file_name]</td><td><code>string</code></td><td><code>null</code></td><td><p>If specified, load the model with this name (excluding the .onnx suffix). Currently only valid for encoder- or decoder-only models.</p>
</td>
</tr><tr>
<td>[device]</td><td><code>*</code></td><td><code></code></td><td><p>The device to run the model on. If not specified, the device will be chosen from the environment settings.</p>
</td>
</tr><tr>
<td>[dtype]</td><td><code>*</code></td><td><code></code></td><td><p>The data type to use for the model. If not specified, the data type will be chosen from the environment settings.</p>
</td>
</tr><tr>
<td>[use_external_data_format]</td><td><code>ExternalData</code> | <code>Record&lt;string, ExternalData&gt;</code></td><td><code>false</code></td><td><p>Whether to load the model using the external data format (used for models &gt;= 2GB in size).</p>
</td>
</tr><tr>
<td>[session_options]</td><td><code>*</code></td><td></td><td><p>(Optional) User-specified session options passed to the runtime. If not provided, suitable defaults will be chosen.</p>
</td>
</tr> </tbody>
</table>
* * *
<a id="module_utils/hub..PretrainedModelOptions" class="group"></a>
## `utils/hub~PretrainedModelOptions` : <code>*</code>
Options for loading a pretrained model.
**Kind**: inner typedef of [<code>utils/hub</code>](#module_utils/hub)
* * *
<EditOnGithub source="https://github.com/huggingface/transformers.js/blob/main/docs/source/api/utils/hub.md" />

Xet Storage Details

Size:
25.9 kB
·
Xet hash:
29c5f406da30be6618a23bdc405de4a429597f207f6888ab86175b403f0b8354

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.