File size: 3,558 Bytes
89ca3a1 4146fdf 89ca3a1 4146fdf 89ca3a1 6795d51 89ca3a1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"machine_shape": "hm",
"gpuType": "T4",
"provenance": []
},
"accelerator": "GPU",
"kaggle": {
"accelerator": "gpu"
},
"language_info": {
"name": "python"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"source": [
"## Custom Notebook by VB on HF\n",
"\n",
"VB made this notebook and Hugging Face gladly served it! yayy!\n",
"\n",
"You can really just do things"
],
"metadata": {
"id": "LJZNGWgrcYeq"
}
},
{
"cell_type": "code",
"source": [
"!pip install -U transformers"
],
"metadata": {
"id": "Qghvxbi8cOVr"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"Model page: https://huggingface.co/reach-vb/Qwen3-0.6B\n",
"\n",
"⚠️ If the generated code snippets do not work, please open an issue on either the [model repo](https://huggingface.co/reach-vb/Qwen3-0.6B)\n",
"\t\t\tand/or on [huggingface.js](https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/src/model-libraries-snippets.ts) 🙏"
],
"metadata": {
"id": "a6SL-cvKcOVr"
}
},
{
"cell_type": "code",
"source": [
"# Use a pipeline as a high-level helper\n",
"from transformers import pipeline\n",
"import torch\n",
"\n",
"pipe = pipeline(\"text-generation\", model=\"reach-vb/Qwen3-0.6B\", torch_dtype=torch.bfloat16)\n",
"messages = [\n",
" {\"role\": \"user\", \"content\": \"Wo bist du, alter?\"},\n",
"]\n",
"pipe(messages, max_new_tokens=512)"
],
"metadata": {
"id": "muWc9vyhcOVr"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Load model directly\n",
"from transformers import AutoTokenizer, AutoModelForCausalLM\n",
"\n",
"tokenizer = AutoTokenizer.from_pretrained(\"reach-vb/Qwen3-0.6B\")\n",
"model = AutoModelForCausalLM.from_pretrained(\"reach-vb/Qwen3-0.6B\")"
],
"metadata": {
"id": "1dy_oF6OcOVs"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Too big to run in Colab?\n",
"\n",
"Try using Inference Providers for serverless usage of these models"
],
"metadata": {
"id": "-r9Z_OnzRSFn"
}
},
{
"cell_type": "code",
"source": [
"import os\n",
"from huggingface_hub import InferenceClient\n",
"\n",
"client = InferenceClient(\n",
" provider=\"auto\",\n",
" api_key=os.environ[\"HF_TOKEN\"],\n",
")\n",
"\n",
"completion = client.chat.completions.create(\n",
" model=\"Qwen/Qwen3-4B\",\n",
" messages=[\n",
" {\n",
" \"role\": \"user\",\n",
" \"content\": \"What is the capital of France?\"\n",
" }\n",
" ],\n",
")\n",
"\n",
"print(completion.choices[0].message)"
],
"metadata": {
"id": "ZtpuYegeRYPg"
},
"execution_count": null,
"outputs": []
}
]
} |