If you haven't already, you can install the
Transformers.js
JavaScript library from
NPM
using:
npm i @huggingface/transformers
Example:
Text generation with
onnx-community/Qwen2.5-Coder-0.5B-Instruct
.
import { pipeline } from"@huggingface/transformers";
// Create a text generation pipelineconst generator = awaitpipeline(
"text-generation",
"onnx-community/Qwen2.5-Coder-0.5B-Instruct",
{ dtype: "q4" },
);
// Define the list of messagesconst messages = [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "Write a quick sort algorithm." },
];
// Generate a responseconst output = awaitgenerator(messages, { max_new_tokens: 512, do_sample: false });
console.log(output[0].generated_text.at(-1).content);
Example output
Here's a simple implementation of the quick sort algorithm in Python:
```python
def quick_sort(arr):
if len(arr) <= 1:
return arr
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
middle = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
return quick_sort(left) + middle + quick_sort(right)
# Example usage:
arr = [3, 6, 8, 10, 1, 2]
sorted_arr = quick_sort(arr)
print(sorted_arr)
```
### Explanation:
- **Base Case**: If the array has less than or equal to one element (i.e., `len(arr)` is less than or equal to `1`), it is already sorted and can be returned as is.
- **Pivot Selection**: The pivot is chosen as the middle element of the array.
- **Partitioning**: The array is partitioned into three parts: elements less than the pivot (`left`), elements equal to the pivot (`middle`), and elements greater than the pivot (`right`). These partitions are then recursively sorted.
- **Recursive Sorting**: The subarrays are sorted recursively using `quick_sort`.
This approach ensures that each recursive call reduces the problem size by half until it reaches a base case.
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using
🤗 Optimum
and structuring your repo like this one (with ONNX weights located in a subfolder named
onnx
).
Runs of onnx-community Qwen2.5-Coder-0.5B-Instruct on huggingface.co
1.6K
Total runs
0
24-hour runs
-2
3-day runs
-9
7-day runs
-9
30-day runs
More Information About Qwen2.5-Coder-0.5B-Instruct huggingface.co Model
Qwen2.5-Coder-0.5B-Instruct huggingface.co
Qwen2.5-Coder-0.5B-Instruct huggingface.co is an AI model on huggingface.co that provides Qwen2.5-Coder-0.5B-Instruct's model effect (), which can be used instantly with this onnx-community Qwen2.5-Coder-0.5B-Instruct model. huggingface.co supports a free trial of the Qwen2.5-Coder-0.5B-Instruct model, and also provides paid use of the Qwen2.5-Coder-0.5B-Instruct. Support call Qwen2.5-Coder-0.5B-Instruct model through api, including Node.js, Python, http.
Qwen2.5-Coder-0.5B-Instruct huggingface.co is an online trial and call api platform, which integrates Qwen2.5-Coder-0.5B-Instruct's modeling effects, including api services, and provides a free online trial of Qwen2.5-Coder-0.5B-Instruct, you can try Qwen2.5-Coder-0.5B-Instruct online for free by clicking the link below.
onnx-community Qwen2.5-Coder-0.5B-Instruct online free url in huggingface.co:
Qwen2.5-Coder-0.5B-Instruct is an open source model from GitHub that offers a free installation service, and any user can find Qwen2.5-Coder-0.5B-Instruct on GitHub to install. At the same time, huggingface.co provides the effect of Qwen2.5-Coder-0.5B-Instruct install, users can directly use Qwen2.5-Coder-0.5B-Instruct installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
Qwen2.5-Coder-0.5B-Instruct install url in huggingface.co: