Update README.md
Browse files
README.md
CHANGED
@@ -16,4 +16,40 @@ This is the same models as the [official phi3 onnx model](https://huggingface.co
|
|
16 |
1. the model is fp16 with int4 block quantization for weights
|
17 |
2. the 'logits' output is fp32
|
18 |
3. the model uses MHA instead of GQA
|
19 |
-
4. onnx and external data file need to stay below 2GB to be cacheable in chromium
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
1. the model is fp16 with int4 block quantization for weights
|
17 |
2. the 'logits' output is fp32
|
18 |
3. the model uses MHA instead of GQA
|
19 |
+
4. onnx and external data file need to stay below 2GB to be cacheable in chromium
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
## Usage (Transformers.js)
|
24 |
+
|
25 |
+
If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@huggingface/transformers) using:
|
26 |
+
```bash
|
27 |
+
npm i @huggingface/transformers
|
28 |
+
```
|
29 |
+
|
30 |
+
You can then use the model to generate text like this:
|
31 |
+
|
32 |
+
```js
|
33 |
+
import { pipeline, TextStreamer } from "@huggingface/transformers";
|
34 |
+
|
35 |
+
// Create a text generation pipeline
|
36 |
+
const generator = await pipeline(
|
37 |
+
"text-generation",
|
38 |
+
"Xenova/Phi-3-mini-4k-instruct",
|
39 |
+
);
|
40 |
+
|
41 |
+
// Define the list of messages
|
42 |
+
const messages = [
|
43 |
+
{ role: "user", content: "Solve the equation: x^2 - 3x + 2 = 0" },
|
44 |
+
];
|
45 |
+
|
46 |
+
// Create text streamer
|
47 |
+
const streamer = new TextStreamer(generator.tokenizer, {
|
48 |
+
skip_prompt: true,
|
49 |
+
// callback_function: (text) => { }, // Optional callback function
|
50 |
+
})
|
51 |
+
|
52 |
+
// Generate a response
|
53 |
+
const output = await generator(messages, { max_new_tokens: 512, do_sample: false, streamer });
|
54 |
+
console.log(output[0].generated_text.at(-1).content);
|
55 |
+
```
|