Skip to content

Commit d516ad7

Browse files
committed
Merge branch 'main' into feat/novita
2 parents 188c967 + ba1ffeb commit d516ad7

File tree

129 files changed

+10163
-7582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+10163
-7582
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Ollama template update
2+
on:
3+
# push: # for debugging
4+
workflow_dispatch:
5+
schedule:
6+
- cron: "0 7 * * 1" # every monday at 7am, so I'll review it after having a 🥐
7+
8+
permissions:
9+
pull-requests: write # for creating PR
10+
issues: write # for adding labels to the created PR
11+
contents: write # for git push new branch
12+
13+
jobs:
14+
update-ollama-templates:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
if: github.repository == 'huggingface/huggingface.js'
19+
20+
- name: Prepare
21+
id: prepare
22+
if: github.repository == 'huggingface/huggingface.js'
23+
shell: bash
24+
run: |
25+
git config --global user.name machineuser
26+
git config --global user.email [email protected]
27+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
28+
npm install -g pnpm
29+
CURRENT_DATE=$(date -u +"%Y-%m-%d")
30+
echo "CURRENT_DATE=$CURRENT_DATE"
31+
echo "CURRENT_DATE=$CURRENT_DATE" >> $GITHUB_OUTPUT
32+
33+
- name: Install dependencies
34+
if: github.repository == 'huggingface/huggingface.js'
35+
shell: bash
36+
run: |
37+
cd packages/ollama-utils
38+
pnpm install --frozen-lockfile
39+
40+
- name: Run update script
41+
if: github.repository == 'huggingface/huggingface.js'
42+
shell: bash
43+
run: |
44+
cd packages/ollama-utils
45+
pnpm run build:automap
46+
47+
- name: Check for changed files
48+
id: changes
49+
if: github.repository == 'huggingface/huggingface.js'
50+
shell: bash
51+
env:
52+
CURRENT_DATE: ${{ steps.prepare.outputs.CURRENT_DATE }}
53+
run: |
54+
set -x
55+
56+
FILE_TO_ADD="packages/ollama-utils/src/chat-template-automap.ts"
57+
58+
git status
59+
modified_files="$(git status -s)"
60+
echo "Modified files: ${modified_files}"
61+
if [ -n "${modified_files}" ]; then
62+
NEW_BRANCH="ollama-${CURRENT_DATE}"
63+
echo "NEW_BRANCH=${NEW_BRANCH}"
64+
echo "Changes detected, will create a new branch:"
65+
echo "${modified_files}"
66+
git add "${FILE_TO_ADD}"
67+
git commit -m "ollama update ${CURRENT_DATE}"
68+
git checkout -b "${NEW_BRANCH}"
69+
git push -f origin "${NEW_BRANCH}"
70+
echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT
71+
echo "NEW_BRANCH=${NEW_BRANCH}" >> $GITHUB_OUTPUT
72+
else
73+
echo "No files changed, skipping..."
74+
echo "HAS_CHANGES=false" >> $GITHUB_OUTPUT
75+
fi
76+
77+
- name: Create PR
78+
if: steps.changes.outputs.HAS_CHANGES == 'true' && github.repository == 'huggingface/huggingface.js'
79+
uses: actions/github-script@v6
80+
env:
81+
CURRENT_DATE: ${{ steps.prepare.outputs.CURRENT_DATE }}
82+
NEW_BRANCH: ${{ steps.changes.outputs.NEW_BRANCH }}
83+
with:
84+
github-token: ${{ secrets.HUGGINGFACE_JS_AUTOMATIC_PR }}
85+
script: |
86+
const { repo, owner } = context.repo;
87+
const currDate = process.env.CURRENT_DATE;
88+
const newBranch = process.env.NEW_BRANCH;
89+
90+
const result = await github.rest.pulls.create({
91+
title: '[ollama-utils] 🤖 Auto-update chat templates (' + currDate + ')',
92+
owner,
93+
repo,
94+
head: newBranch,
95+
base: 'main',
96+
body: [
97+
'This PR is auto-generated by',
98+
'[generate-automap.ts](https://github.com/huggingface/huggingface.js/blob/main/packages/ollama-utils/scripts/generate-automap.ts).'
99+
].join('\n')
100+
});
101+
102+
console.log({ result });
103+
// github.rest.issues.addLabels({
104+
// owner,
105+
// repo,
106+
// issue_number: result.data.number,
107+
// labels: ['feature', 'automated pr']
108+
// });
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Ollama Utils - Version and Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
newversion:
7+
type: choice
8+
description: "Semantic Version Bump Type"
9+
default: patch
10+
options:
11+
- patch
12+
- minor
13+
- major
14+
15+
concurrency:
16+
group: "push-to-main"
17+
18+
defaults:
19+
run:
20+
working-directory: packages/ollama-utils
21+
22+
jobs:
23+
version_and_release:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v3
27+
with:
28+
# Needed to push the tag and the commit on the main branch, otherwise we get:
29+
# > Run git push --follow-tags
30+
# remote: error: GH006: Protected branch update failed for refs/heads/main.
31+
# remote: error: Changes must be made through a pull request. Required status check "lint" is expected.
32+
token: ${{ secrets.BOT_ACCESS_TOKEN }}
33+
- run: npm install -g corepack@latest && corepack enable
34+
- uses: actions/setup-node@v3
35+
with:
36+
node-version: "20"
37+
cache: "pnpm"
38+
cache-dependency-path: |
39+
packages/ollama-utils/pnpm-lock.yaml
40+
# setting a registry enables the NODE_AUTH_TOKEN env variable where we can set an npm token. REQUIRED
41+
registry-url: "https://registry.npmjs.org"
42+
- run: pnpm install
43+
- run: git config --global user.name machineuser
44+
- run: git config --global user.email [email protected]
45+
- run: |
46+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
47+
BUMPED_VERSION=$(node -p "require('semver').inc('$PACKAGE_VERSION', '${{ github.event.inputs.newversion }}')")
48+
# Update package.json with the new version
49+
node -e "const fs = require('fs'); const package = JSON.parse(fs.readFileSync('./package.json')); package.version = '$BUMPED_VERSION'; fs.writeFileSync('./package.json', JSON.stringify(package, null, '\t') + '\n');"
50+
git commit . -m "🔖 @huggingface/ollama-utils $BUMPED_VERSION"
51+
git tag "ollama-utils-v$BUMPED_VERSION"
52+
53+
- name: "Check Deps are published before publishing this package"
54+
run: pnpm -w check-deps tasks
55+
56+
- run: pnpm publish --no-git-checks .
57+
env:
58+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
59+
- run: git pull --rebase && git push --follow-tags
60+
# hack - reuse actions/setup-node@v3 just to set a new registry
61+
- uses: actions/setup-node@v3
62+
with:
63+
node-version: "20"
64+
registry-url: "https://npm.pkg.github.com"
65+
# Disable for now, until github supports PATs for writing github packages (https://github.com/github/roadmap/issues/558)
66+
# - run: pnpm publish --no-git-checks .
67+
# env:
68+
# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ jobs:
4141
run: VCR_MODE=playback pnpm --filter ...[${{ steps.since.outputs.SINCE }}] test
4242
env:
4343
HF_TOKEN: ${{ secrets.HF_TOKEN }}
44-
HF_FAL_KEY: dummy
45-
HF_NEBIUS_KEY: dummy
46-
HF_REPLICATE_KEY: dummy
47-
HF_SAMBANOVA_KEY: dummy
48-
HF_TOGETHER_KEY: dummy
49-
HF_NOVITA_KEY: dummy
50-
HF_FIREWORKS_KEY: dummy
5144

5245
browser:
5346
runs-on: ubuntu-latest
@@ -84,13 +77,6 @@ jobs:
8477
run: VCR_MODE=playback pnpm --filter ...[${{ steps.since.outputs.SINCE }}] test:browser
8578
env:
8679
HF_TOKEN: ${{ secrets.HF_TOKEN }}
87-
HF_FAL_KEY: dummy
88-
HF_NEBIUS_KEY: dummy
89-
HF_REPLICATE_KEY: dummy
90-
HF_SAMBANOVA_KEY: dummy
91-
HF_TOGETHER_KEY: dummy
92-
HF_NOVITA_KEY: dummy
93-
HF_FIREWORKS_KEY: dummy
9480

9581
e2e:
9682
runs-on: ubuntu-latest
@@ -154,10 +140,3 @@ jobs:
154140
env:
155141
NPM_CONFIG_REGISTRY: http://localhost:4874/
156142
HF_TOKEN: ${{ secrets.HF_TOKEN }}
157-
HF_FAL_KEY: dummy
158-
HF_NEBIUS_KEY: dummy
159-
HF_REPLICATE_KEY: dummy
160-
HF_SAMBANOVA_KEY: dummy
161-
HF_TOGETHER_KEY: dummy
162-
HF_NOVITA_KEY: dummy
163-
HF_FIREWORKS_KEY: dummy

CODEOWNERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@
2323
/packages/gguf @mishig25 @ngxson @julien-c
2424

2525
# Ownership for the space-header Package
26+
2627
/packages/space-header @enzostvs
28+
29+
# Ownership for the ollama-utils Package
30+
31+
/packages/ollama-utils @ngxson

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ await uploadFile({
2323
// Can work with native File in browsers
2424
file: {
2525
path: "pytorch_model.bin",
26-
content: new Blob(...)
26+
content: new Blob(...)
2727
}
2828
});
2929

@@ -39,7 +39,7 @@ await inference.chatCompletion({
3939
],
4040
max_tokens: 512,
4141
temperature: 0.5,
42-
provider: "sambanova", // or together, fal-ai, replicate, …
42+
provider: "sambanova", // or together, fal-ai, replicate, cohere
4343
});
4444

4545
await inference.textToImage({
@@ -96,7 +96,7 @@ You can run our packages with vanilla JS, without any bundler, by using a CDN or
9696

9797
```html
9898
<script type="module">
99-
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@3.3.3/+esm';
99+
import { HfInference } from 'https://cdn.jsdelivr.net/npm/@huggingface/inference@3.5.1/+esm';
100100
import { createRepo, commit, deleteRepo, listFiles } from "https://cdn.jsdelivr.net/npm/@huggingface/[email protected]/+esm";
101101
</script>
102102
```
@@ -146,12 +146,12 @@ for await (const chunk of inference.chatCompletionStream({
146146
console.log(chunk.choices[0].delta.content);
147147
}
148148

149-
/// Using a third-party provider:
149+
/// Using a third-party provider:
150150
await inference.chatCompletion({
151151
model: "meta-llama/Llama-3.1-8B-Instruct",
152152
messages: [{ role: "user", content: "Hello, nice to meet you!" }],
153153
max_tokens: 512,
154-
provider: "sambanova", // or together, fal-ai, replicate, …
154+
provider: "sambanova", // or together, fal-ai, replicate, cohere
155155
})
156156

157157
await inference.textToImage({
@@ -211,7 +211,7 @@ await uploadFile({
211211
// Can work with native File in browsers
212212
file: {
213213
path: "pytorch_model.bin",
214-
content: new Blob(...)
214+
content: new Blob(...)
215215
}
216216
});
217217

@@ -244,7 +244,7 @@ console.log(messages); // contains the data
244244

245245
// or you can run the code directly, however you can't check that the code is safe to execute this way, use at your own risk.
246246
const messages = await agent.run("Draw a picture of a cat wearing a top hat. Then caption the picture and read it out loud.")
247-
console.log(messages);
247+
console.log(messages);
248248
```
249249

250250
There are more features of course, check each library's README!

e2e/ts/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2015",
3+
"target": "ES2022",
44
"module": "commonjs",
55
"strict": true,
66
"esModuleInterop": true,

packages/gguf/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,52 @@ In case you want to use your own GGUF metadata structure, you can disable strict
9696
const { metadata, tensorInfos }: GGUFParseOutput<{ strict: false }> = await gguf(URL_LLAMA);
9797
```
9898

99+
## Command line interface
100+
101+
This package provides a CLI equivalent to [`gguf_dump.py`](https://github.com/ggml-org/llama.cpp/blob/7a2c913e66353362d7f28d612fd3c9d51a831eda/gguf-py/gguf/scripts/gguf_dump.py) script. You can dump GGUF metadata and list of tensors using this command:
102+
103+
```bash
104+
npx @huggingface/gguf my_model.gguf
105+
106+
# or, with a remote GGUF file:
107+
# npx @huggingface/gguf https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF/resolve/main/Llama-3.2-1B-Instruct-Q4_K_M.gguf
108+
```
109+
110+
Example for the output:
111+
112+
```
113+
* Dumping 36 key/value pair(s)
114+
Idx | Count | Value
115+
----|--------|----------------------------------------------------------------------------------
116+
1 | 1 | version = 3
117+
2 | 1 | tensor_count = 292
118+
3 | 1 | kv_count = 33
119+
4 | 1 | general.architecture = "llama"
120+
5 | 1 | general.type = "model"
121+
6 | 1 | general.name = "Meta Llama 3.1 8B Instruct"
122+
7 | 1 | general.finetune = "Instruct"
123+
8 | 1 | general.basename = "Meta-Llama-3.1"
124+
125+
[truncated]
126+
127+
* Dumping 292 tensor(s)
128+
Idx | Num Elements | Shape | Data Type | Name
129+
----|--------------|--------------------------------|-----------|--------------------------
130+
1 | 64 | 64, 1, 1, 1 | F32 | rope_freqs.weight
131+
2 | 525336576 | 4096, 128256, 1, 1 | Q4_K | token_embd.weight
132+
3 | 4096 | 4096, 1, 1, 1 | F32 | blk.0.attn_norm.weight
133+
4 | 58720256 | 14336, 4096, 1, 1 | Q6_K | blk.0.ffn_down.weight
134+
135+
[truncated]
136+
```
137+
138+
Alternatively, you can install this package as global, which will provide the `gguf-view` command:
139+
140+
```bash
141+
npm i -g @huggingface/gguf
142+
gguf-view my_model.gguf
143+
```
144+
99145
## Hugging Face Hub
100146

101147
The Hub supports all file formats and has built-in features for GGUF format.

packages/gguf/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@huggingface/gguf",
33
"packageManager": "[email protected]",
4-
"version": "0.1.12",
4+
"version": "0.1.13",
55
"description": "a GGUF parser that works on remotely hosted files",
66
"repository": "https://github.com/huggingface/huggingface.js.git",
77
"publishConfig": {
@@ -10,6 +10,9 @@
1010
"main": "./dist/index.js",
1111
"module": "./dist/index.mjs",
1212
"types": "./dist/index.d.ts",
13+
"bin": {
14+
"gguf-view": "./dist/cli.js"
15+
},
1316
"exports": {
1417
".": {
1518
"types": "./dist/index.d.ts",
@@ -18,6 +21,7 @@
1821
}
1922
},
2023
"browser": {
24+
"./src/cli.ts": false,
2125
"./src/utils/FileBlob.ts": false,
2226
"./dist/index.js": "./dist/browser/index.js",
2327
"./dist/index.mjs": "./dist/browser/index.mjs"
@@ -32,7 +36,7 @@
3236
"format": "prettier --write .",
3337
"format:check": "prettier --check .",
3438
"prepublishOnly": "pnpm run build",
35-
"build": "tsup src/index.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration",
39+
"build": "tsup src/index.ts src/cli.ts --format cjs,esm --clean && tsc --emitDeclarationOnly --declaration",
3640
"build:llm": "tsx scripts/generate-llm.ts && pnpm run format",
3741
"test": "vitest run",
3842
"check": "tsc"

0 commit comments

Comments
 (0)