Add notebook
Browse filesThis will let users launch Colab with working snippet 🙏🏻
- notebook.ipynb +67 -0
notebook.ipynb
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"nbformat": 4,
|
| 3 |
+
"nbformat_minor": 0,
|
| 4 |
+
"metadata": {
|
| 5 |
+
"colab": {
|
| 6 |
+
"machine_shape": "hm",
|
| 7 |
+
"gpuType": "T4",
|
| 8 |
+
"provenance": []
|
| 9 |
+
},
|
| 10 |
+
"accelerator": "GPU",
|
| 11 |
+
"kaggle": {
|
| 12 |
+
"accelerator": "gpu"
|
| 13 |
+
},
|
| 14 |
+
"language_info": {
|
| 15 |
+
"name": "python"
|
| 16 |
+
},
|
| 17 |
+
"kernelspec": {
|
| 18 |
+
"name": "python3",
|
| 19 |
+
"display_name": "Python 3"
|
| 20 |
+
}
|
| 21 |
+
},
|
| 22 |
+
"cells": [
|
| 23 |
+
{
|
| 24 |
+
"cell_type": "code",
|
| 25 |
+
"source": [
|
| 26 |
+
"!pip install -U transformers"
|
| 27 |
+
],
|
| 28 |
+
"metadata": {
|
| 29 |
+
"id": "4LXugJ1wUN5o"
|
| 30 |
+
},
|
| 31 |
+
"execution_count": null,
|
| 32 |
+
"outputs": []
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"cell_type": "markdown",
|
| 36 |
+
"source": [
|
| 37 |
+
"## Local Inference on GPU\n",
|
| 38 |
+
"Model page: https://huggingface.co/vikhyatk/moondream2\n",
|
| 39 |
+
"\n",
|
| 40 |
+
"⚠️ If the generated code snippets do not work, please open an issue on either the [model repo](https://huggingface.co/vikhyatk/moondream2)\n",
|
| 41 |
+
"\t\t\tand/or on [huggingface.js](https://github.com/huggingface/huggingface.js/blob/main/packages/tasks/src/model-libraries-snippets.ts) 🙏"
|
| 42 |
+
],
|
| 43 |
+
"metadata": {
|
| 44 |
+
"id": "t490XrsVUN5q"
|
| 45 |
+
}
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"cell_type": "code",
|
| 49 |
+
"source": [
|
| 50 |
+
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
|
| 51 |
+
"\n",
|
| 52 |
+
"tokenizer = AutoTokenizer.from_pretrained(\"vikhyatk/moondream2\")\n",
|
| 53 |
+
"model = AutoModelForCausalLM.from_pretrained(\n",
|
| 54 |
+
" \"vikhyatk/moondream2\",\n",
|
| 55 |
+
" revision=\"2025-06-21\",\n",
|
| 56 |
+
" trust_remote_code=True,\n",
|
| 57 |
+
" device_map={\"\": \"cuda\"}\n",
|
| 58 |
+
")"
|
| 59 |
+
],
|
| 60 |
+
"metadata": {
|
| 61 |
+
"id": "6aWNuxB8UN5s"
|
| 62 |
+
},
|
| 63 |
+
"execution_count": null,
|
| 64 |
+
"outputs": []
|
| 65 |
+
}
|
| 66 |
+
]
|
| 67 |
+
}
|