Add Colab quickstart, chat template, and release metadata
Browse files- Vortex_Alpha_Colab.ipynb +147 -0
- chat_template.jinja +13 -0
- requirements.txt +4 -0
- tokenizer_config.json +1 -0
Vortex_Alpha_Colab.ipynb
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# Vortex Alpha\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"A compact, experimental 174.9M-parameter language model. The final public name is still undecided.\n",
|
| 10 |
+
"\n",
|
| 11 |
+
"This notebook loads the public Hugging Face checkpoint with the standard Transformers API. Vortex is a research preview: expect factual, arithmetic, repetition, and long-context errors."
|
| 12 |
+
]
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"cell_type": "markdown",
|
| 16 |
+
"metadata": {},
|
| 17 |
+
"source": [
|
| 18 |
+
"## 1. Install the small runtime\n",
|
| 19 |
+
"\n",
|
| 20 |
+
"On Colab, select a GPU runtime when available. The model is small enough to fit comfortably in a typical Colab GPU, although this reference implementation does not use a KV cache."
|
| 21 |
+
]
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"cell_type": "code",
|
| 25 |
+
"execution_count": null,
|
| 26 |
+
"metadata": {},
|
| 27 |
+
"outputs": [],
|
| 28 |
+
"source": [
|
| 29 |
+
"%pip -q install -U \"transformers>=4.45\" sentencepiece safetensors"
|
| 30 |
+
]
|
| 31 |
+
},
|
| 32 |
+
{
|
| 33 |
+
"cell_type": "markdown",
|
| 34 |
+
"metadata": {},
|
| 35 |
+
"source": [
|
| 36 |
+
"## 2. Load Vortex from the Hub\n",
|
| 37 |
+
"\n",
|
| 38 |
+
"`trust_remote_code=True` is required because Vortex has a custom GQA + QK-Norm implementation. The repository contains the configuration, model, tokenizer, and generation code used here."
|
| 39 |
+
]
|
| 40 |
+
},
|
| 41 |
+
{
|
| 42 |
+
"cell_type": "code",
|
| 43 |
+
"execution_count": null,
|
| 44 |
+
"metadata": {},
|
| 45 |
+
"outputs": [],
|
| 46 |
+
"source": [
|
| 47 |
+
"import torch\n",
|
| 48 |
+
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
|
| 49 |
+
"\n",
|
| 50 |
+
"REPO = \"North-ML1/vortex-alpha\"\n",
|
| 51 |
+
"if torch.cuda.is_available():\n",
|
| 52 |
+
" device = torch.device(\"cuda\")\n",
|
| 53 |
+
" dtype = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16\n",
|
| 54 |
+
"else:\n",
|
| 55 |
+
" device = torch.device(\"cpu\")\n",
|
| 56 |
+
" dtype = torch.float32\n",
|
| 57 |
+
"\n",
|
| 58 |
+
"tokenizer = AutoTokenizer.from_pretrained(REPO, trust_remote_code=True)\n",
|
| 59 |
+
"model = AutoModelForCausalLM.from_pretrained(\n",
|
| 60 |
+
" REPO, trust_remote_code=True, torch_dtype=dtype\n",
|
| 61 |
+
").to(device).eval()\n",
|
| 62 |
+
"\n",
|
| 63 |
+
"print(\"device:\", device)\n",
|
| 64 |
+
"print(\"dtype:\", next(model.parameters()).dtype)\n",
|
| 65 |
+
"print(\"parameters:\", model.num_parameters())\n",
|
| 66 |
+
"print(\"tokenizer vocabulary:\", tokenizer.vocab_size)"
|
| 67 |
+
]
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"cell_type": "markdown",
|
| 71 |
+
"metadata": {},
|
| 72 |
+
"source": [
|
| 73 |
+
"## 3. Ask a question with the built-in chat template"
|
| 74 |
+
]
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"cell_type": "code",
|
| 78 |
+
"execution_count": null,
|
| 79 |
+
"metadata": {},
|
| 80 |
+
"outputs": [],
|
| 81 |
+
"source": [
|
| 82 |
+
"def ask(question: str, max_new_tokens: int = 96) -> str:\n",
|
| 83 |
+
" messages = [{\"role\": \"user\", \"content\": question}]\n",
|
| 84 |
+
" prompt = tokenizer.apply_chat_template(\n",
|
| 85 |
+
" messages, tokenize=False, add_generation_prompt=True\n",
|
| 86 |
+
" )\n",
|
| 87 |
+
" inputs = tokenizer(prompt, return_tensors=\"pt\").to(device)\n",
|
| 88 |
+
" with torch.inference_mode():\n",
|
| 89 |
+
" generated = model.generate(\n",
|
| 90 |
+
" **inputs,\n",
|
| 91 |
+
" max_new_tokens=max_new_tokens,\n",
|
| 92 |
+
" do_sample=False,\n",
|
| 93 |
+
" pad_token_id=tokenizer.pad_token_id,\n",
|
| 94 |
+
" eos_token_id=tokenizer.eos_token_id,\n",
|
| 95 |
+
" )\n",
|
| 96 |
+
" new_tokens = generated[0, inputs[\"input_ids\"].shape[1]:]\n",
|
| 97 |
+
" return tokenizer.decode(new_tokens, skip_special_tokens=True)\n",
|
| 98 |
+
"\n",
|
| 99 |
+
"print(ask(\"Explain why the sky appears blue in two short paragraphs.\"))"
|
| 100 |
+
]
|
| 101 |
+
},
|
| 102 |
+
{
|
| 103 |
+
"cell_type": "code",
|
| 104 |
+
"execution_count": null,
|
| 105 |
+
"metadata": {},
|
| 106 |
+
"outputs": [],
|
| 107 |
+
"source": [
|
| 108 |
+
"questions = [\n",
|
| 109 |
+
" \"Solve 3x + 5 = 20 and show the steps.\",\n",
|
| 110 |
+
" \"Write a short Python function that returns the largest number in a list.\",\n",
|
| 111 |
+
" \"Summarize: The museum opens at 9, closes at 5, and admission is free on Sunday.\",\n",
|
| 112 |
+
"]\n",
|
| 113 |
+
"for question in questions:\n",
|
| 114 |
+
" print(f\"\\nUSER: {question}\\nVORTEX: {ask(question)}\")"
|
| 115 |
+
]
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"cell_type": "markdown",
|
| 119 |
+
"metadata": {},
|
| 120 |
+
"source": [
|
| 121 |
+
"## Notes\n",
|
| 122 |
+
"\n",
|
| 123 |
+
"- `model.safetensors` is the experimental instruction/tool-format preview.\n",
|
| 124 |
+
"- `base_model.safetensors` is the corresponding pretrained base; the notebook loads the instruction preview by default.\n",
|
| 125 |
+
"- The model may emit a `CALL {json}` tool request, but this notebook does not provide external tools.\n",
|
| 126 |
+
"- Do not rely on Vortex for medical, legal, financial, or other high-stakes decisions."
|
| 127 |
+
]
|
| 128 |
+
}
|
| 129 |
+
],
|
| 130 |
+
"metadata": {
|
| 131 |
+
"accelerator": "GPU",
|
| 132 |
+
"colab": {
|
| 133 |
+
"gpuType": "T4",
|
| 134 |
+
"provenance": []
|
| 135 |
+
},
|
| 136 |
+
"kernelspec": {
|
| 137 |
+
"display_name": "Python 3",
|
| 138 |
+
"language": "python",
|
| 139 |
+
"name": "python3"
|
| 140 |
+
},
|
| 141 |
+
"language_info": {
|
| 142 |
+
"name": "python"
|
| 143 |
+
}
|
| 144 |
+
},
|
| 145 |
+
"nbformat": 4,
|
| 146 |
+
"nbformat_minor": 5
|
| 147 |
+
}
|
chat_template.jinja
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{%- if messages and messages[0]['role'] != 'system' %}
|
| 2 |
+
[SYSTEM]
|
| 3 |
+
You are a helpful assistant. Answer clearly and say when information is missing.
|
| 4 |
+
</s>
|
| 5 |
+
{%- endif %}
|
| 6 |
+
{%- for message in messages %}
|
| 7 |
+
[{{ message['role']|upper }}]
|
| 8 |
+
{{ message['content'] }}
|
| 9 |
+
</s>
|
| 10 |
+
{%- endfor %}
|
| 11 |
+
{%- if add_generation_prompt %}
|
| 12 |
+
[ASSISTANT]
|
| 13 |
+
{%- endif %}
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch>=2.1
|
| 2 |
+
transformers>=4.45
|
| 3 |
+
sentencepiece>=0.2
|
| 4 |
+
safetensors>=0.4
|
tokenizer_config.json
CHANGED
|
@@ -10,6 +10,7 @@
|
|
| 10 |
"pad_token": "</s>",
|
| 11 |
"model_max_length": 4096,
|
| 12 |
"padding_side": "left",
|
|
|
|
| 13 |
"add_bos_token": false,
|
| 14 |
"add_eos_token": false
|
| 15 |
}
|
|
|
|
| 10 |
"pad_token": "</s>",
|
| 11 |
"model_max_length": 4096,
|
| 12 |
"padding_side": "left",
|
| 13 |
+
"chat_template": "{%- if messages and messages[0]['role'] != 'system' %}[SYSTEM]\nYou are a helpful assistant. Answer clearly and say when information is missing.\n</s>\n{%- endif %}{%- for message in messages %}[{{ message['role']|upper }}]\n{{ message['content'] }}\n</s>\n{%- endfor %}{%- if add_generation_prompt %}[ASSISTANT]\n{%- endif %}",
|
| 14 |
"add_bos_token": false,
|
| 15 |
"add_eos_token": false
|
| 16 |
}
|