Skip to content

Commit 59397eb

Browse files
authored
Merge branch 'main' into fix-widget-model-for-image-text-to-text
2 parents bbea494 + dda925a commit 59397eb

File tree

6 files changed

+65
-4
lines changed

6 files changed

+65
-4
lines changed

.github/workflows/tasks-publish.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,44 @@ jobs:
4949
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');"
5050
git commit . -m "🔖 @huggingface/tasks $BUMPED_VERSION"
5151
git tag "tasks-v$BUMPED_VERSION"
52+
53+
- name: Make sure that the latest version of @huggingface/gguf is consistent with the local version
54+
run: |
55+
LOCAL_GGUF_VERSION=$(node -p "require('./package.json').version")
56+
REMOTE_GGUF_VERSION=$(npm view @huggingface/gguf version)
57+
58+
# If the versions are different, error
59+
if [ "$LOCAL_GGUF_VERSION" != "$REMOTE_GGUF_VERSION" ]; then
60+
echo "Error: The local @huggingface/gguf package version ($LOCAL_GGUF_VERSION) differs from the remote version ($REMOTE_GGUF_VERSION). Release halted."
61+
exit 1
62+
fi
63+
64+
npm pack @huggingface/gguf
65+
mv huggingface-gguf-$LOCAL_GGUF_VERSION.tgz gguf-local.tgz
66+
67+
npm pack @huggingface/gguf@$REMOTE_GGUF_VERSION
68+
mv huggingface-gguf-$REMOTE_GGUF_VERSION.tgz gguf-remote.tgz
69+
70+
# Compute checksum of local tar. We need to extract both tar since the remote compression might be different
71+
tar -xf gguf-local.tgz
72+
LOCAL_CHECKSUM=$(cd package && tar --mtime='1970-01-01' --mode=755 -cf - . | sha256sum | cut -d' ' -f1)
73+
echo "Local package checksum: $LOCAL_CHECKSUM"
74+
75+
rm -Rf package
76+
77+
tar -xf gguf-remote.tgz
78+
REMOTE_CHECKSUM=$(cd package && tar --mtime='1970-01-01' --mode=755 -cf - . | sha256sum | cut -d' ' -f1)
79+
echo "Remote package checksum: $REMOTE_CHECKSUM"
80+
81+
rm -Rf package
82+
83+
if [ "$LOCAL_CHECKSUM" != "$REMOTE_CHECKSUM" ]; then
84+
echo "Checksum Verification Failed: The local @huggingface/gguf package differs from the remote version. Release halted. Local Checksum: $LOCAL_CHECKSUM, Remote Checksum: $REMOTE_CHECKSUM"
85+
exit 1
86+
fi
87+
echo "Checksum Verification Successful: The local and remote @huggingface/gguf packages are consistent. Proceeding with the @huggingface/widgets package release. Local Checksum: $LOCAL_CHECKSUM, Remote Checksum: $REMOTE_CHECKSUM."
88+
working-directory: packages/gguf
89+
5290
- run: pnpm publish --no-git-checks .
5391
env:
5492
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
run: |
106106
sleep 3
107107
pnpm i --filter root --filter inference... --filter hub... --frozen-lockfile
108-
pnpm --filter inference --filter hub --filter tasks publish --force --no-git-checks --registry http://localhost:4874/
108+
pnpm --filter inference --filter hub --filter tasks --filter gguf publish --force --no-git-checks --registry http://localhost:4874/
109109
110110
- name: E2E test - test yarn install
111111
working-directory: e2e/ts

e2e/deno/deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

e2e/mock-registry-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ auth:
44
foo:
55
name: test
66
password: test
7+
web:
8+
# login with foo / test
9+
enable: true
710
store:
811
memory:
912
limit: 1000

packages/tasks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@huggingface/tasks",
33
"packageManager": "[email protected]",
4-
"version": "0.12.22",
4+
"version": "0.12.23",
55
"description": "List of ML tasks for huggingface.co/tasks",
66
"repository": "https://github.com/huggingface/huggingface.js.git",
77
"publishConfig": {

packages/tasks/src/model-libraries-snippets.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ModelData } from "./model-data";
2-
import type { WidgetExampleTextInput } from "./widget-example";
2+
import type { WidgetExampleTextInput, WidgetExampleSentenceSimilarityInput } from "./widget-example";
33
import { LIBRARY_TASK_MAPPING } from "./library-to-tasks";
44

55
const TAG_CUSTOM_CODE = "custom_code";
@@ -704,13 +704,32 @@ export const sampleFactory = (model: ModelData): string[] => [
704704
`python -m sample_factory.huggingface.load_from_hub -r ${model.id} -d ./train_dir`,
705705
];
706706

707+
function get_widget_examples_from_st_model(model: ModelData): string[] | undefined {
708+
const widgetExample = model.widgetData?.[0] as WidgetExampleSentenceSimilarityInput | undefined;
709+
if (widgetExample) {
710+
return [widgetExample.source_sentence, ...widgetExample.sentences];
711+
}
712+
}
713+
707714
export const sentenceTransformers = (model: ModelData): string[] => {
708715
const remote_code_snippet = model.tags.includes(TAG_CUSTOM_CODE) ? ", trust_remote_code=True" : "";
716+
const exampleSentences = get_widget_examples_from_st_model(model) ?? [
717+
"The weather is lovely today.",
718+
"It's so sunny outside!",
719+
"He drove to the stadium.",
720+
];
709721

710722
return [
711723
`from sentence_transformers import SentenceTransformer
712724
713-
model = SentenceTransformer("${model.id}"${remote_code_snippet})`,
725+
model = SentenceTransformer("${model.id}"${remote_code_snippet})
726+
727+
sentences = ${JSON.stringify(exampleSentences, null, 4)}
728+
embeddings = model.encode(sentences)
729+
730+
similarities = model.similarity(embeddings, embeddings)
731+
print(similarities.shape)
732+
# [${exampleSentences.length}, ${exampleSentences.length}]`,
714733
];
715734
};
716735

0 commit comments

Comments
 (0)