Sync token-free public demo
Browse files3 unmodified lines456789101112131415161718192021221 unmodified line2425262728293011 unmodified lines424344454647484950515253545556575859601 unmodified line6263646566676869707172737475767778798081828384858687881 unmodified line9091929394959623 unmodified lines1201211221231241251263 unmodified lines"cell_type": "markdown","id": "title","metadata": {},"source": "# Try TheSystem — Probe-256\n\nThis notebook is for readers who want to try the released model without training it.\nYou will load its exact weights, submit a writing request and a decision request,\nthen edit an example to see how `<FAST>` chooses a response mode.\n\nThe frozen Qwen backbone feeds a classifier with one 256-unit hidden layer. There are no LoRA modules in this model. The selected checkpoint is seed 42, epoch 6. Both release models use the same selected diverse-42 `<FAST>` gate.\n"},{"cell_type": "markdown","id": "prerequisites","metadata": {},"source": "## Before you start\n\nSelect **Runtime → Change runtime type → latest runtime version → NVIDIA GPU**.\nUse Linux, Python 3.12 or 3.13 and native BF16 support. A **24 GB GPU may be tried**;\nthere is no minimum-memory cutoff. This capacity has not yet been validated for\nthese demos. Free T4 runtimes lack native BF16 support and are unsupported.\n\nBF16 weights alone use about 18 GB. Loading and requests need extra GPU memory,\nwhich depends on the prompt and response length. Setup reports total/free memory;\n**READY** confirms the software and GPU checks, not that the model will fit.\nKeep only one model loaded. Allow about 18 GB of disk space for the backbone plus caches.\n\nStart with a fresh runtime. This demo reuses Colab's PyTorch 2.14.x and NumPy. Setup installs only the inference\npackages it needs, without compiling CUDA extensions or running training checks.\nThe selected weights and prompt format are unchanged. Built-in PyTorch operations\ncan be slower and may give small numerical differences from the research kernels.\nUse notebook 03 for reproducing the published measurements.\n\nRun the cells in order. During private staging, enter a Hugging Face **read token**\nfrom an account with access to this model repository. Keep the token private.\n"},{"cell_type": "markdown","id": "prepare-intro","metadata": {},"source": "## 1. Prepare runtime\n\nRun this cell and enter your **Hugging Face read token** in its hidden prompt\n([token settings](https://huggingface.co/settings/tokens)). It checks the GPU,\ninstalls missing inference packages, and verifies the downloaded release wheel.\nProgress and elapsed-time updates appear every 20 seconds; details are saved in\n`thesystem-prepare-runtime.log`.\n\nContinue when it says **READY**. A fresh Colab session normally needs no restart.\nIf this session already imported an older package, setup will explain how to\nrestart once and rerun the cell. No compiler setup or separate NumPy upgrade is needed.\n"},{"cell_type": "code",1 unmodified line"metadata": {"cellView": "form"},"source": "# @title Prepare runtime\nRUNTIME_READY = False\nimport getpass, hashlib, os, sys\nfrom urllib.request import Request, urlopen\nfrom urllib.error import HTTPError, URLError\n\nPREPARE = {'repo_id': 'Lbuk/TheSystem-9B-Probe-256', 'revision': '39ce46e600a9ad7a2d5bf216b17bef71fe40b599', 'sha256': 'a0d1904552b5296ba7c3555fac79bb770b1a4efb75005a5d57e3580b7b3574bc'}\nprint(\"Prepare runtime: checking Python, then opening private setup access…\", flush=True)\nif sys.version_info[:2] not in ((3, 12), (3, 13)):\n raise RuntimeError(\"Use Python 3.12 or 3.13: Colab Runtime → Change runtime type → the latest runtime version.\")\nos.environ[\"HF_TOKEN\"] = getpass.getpass(\"Hugging Face read token (hidden; Enter only for public access): \").strip()\nprint(\"Downloading the small, pinned setup helper (30-second timeout)…\", flush=True)\nurl = f\"https://huggingface.co/{PREPARE['repo_id']}/resolve/{PREPARE['revision']}/prepare_runtime.py\"\nheaders = {\"Authorization\": f\"Bearer {os.environ['HF_TOKEN']}\"} if os.environ[\"HF_TOKEN\"] else {}\ntry:\n with urlopen(Request(url, headers=headers), timeout=30) as response:\n helper = response.read()\nexcept HTTPError as error:\n raise RuntimeError(\"Setup download failed. For HTTP 401/403, rerun this cell and paste a valid read token for this private repository. \"\n f\"HTTP status: {error.code}. Your browser login is separate from Colab.\") from None\nexcept (URLError, TimeoutError) as error:\n raise RuntimeError(\"Setup helper download failed or timed out. Check the connection and rerun Prepare runtime.\") from None\nif hashlib.sha256(helper).hexdigest() != PREPARE[\"sha256\"]:\n raise RuntimeError(\"Setup helper checksum mismatch. Stop and obtain a fresh release notebook.\")\n_setup = {\"__name__\": \"thesystem_demo_setup\"}\nexec(compile(helper, \"prepare_runtime.py\", \"exec\"), _setup)\nvisible_progress = _setup[\"visible_progress\"]\ntorch = _setup[\"prepare_runtime\"](\"probe\")\n\nRUNTIME_READY = True","outputs": [],"execution_count": null},11 unmodified lines"outputs": [],"source": "if not globals().get(\"RUNTIME_READY\", False):\n raise RuntimeError(\"Run Prepare runtime until it reports READY before loading the model.\")\n\nfrom thesystem import load_model\nfrom thesystem.artifacts import resolve_model_resources\n\nif globals().get(\"model\") is not None:\n if getattr(model, \"variant\", None) != \"probe\":\n raise RuntimeError(\"A different model is already loaded. Restart the session before loading this model.\")\n print(\"Reusing the loaded model; continue to the examples.\")\nelse:\n with visible_progress(\"Download and load the selected model\"):\n RESOURCE_ROOT = resolve_model_resources(\"probe\")\n model = load_model(\"probe\", root=RESOURCE_ROOT, execution=\"inference\")\n print(\"Loaded the selected Probe-256 checkpoint with the shared <FAST> gate.\")\n"},{"cell_type": "code","id": "display-response","metadata": {},"execution_count": null,"outputs": [],"source": "def show_response(result):\n print(\"Selected mode:\", result[\"mode\"])\n score = result.get(\"gate_probability\")\n if score is not None:\n print(f\"<FAST> score: {float(score):.4f} (decision threshold: 0.5)\")\n if result.get(\"selected_code\") is not None:\n print(\"Selected choice:\", result[\"selected_code\"])\n if result[\"mode\"] == \"unsupported\":\n print(\"The gate selected decision mode without usable supplied choices. No generation fallback was applied.\")\n else:\n print(\"Response:\", result.get(\"answer\", result))\n if result.get(\"hit_limit\"):\n print(\"The generated response reached its token limit.\")\n"},{"cell_type": "markdown","id": "writing-intro","metadata": {},"source": "## 3. Try a writing request\n\nAutomatic mode lets `<FAST>` choose whether to select an answer or generate text.\nHere we ask for a short reply. The gate score is a routing score, not confidence\nthat the content of the answer is correct.\n"},{"cell_type": "code",1 unmodified line"metadata": {},"execution_count": null,"outputs": [],"source": "writing_prompt = \"Write a short reply to a customer whose API key is being rejected.\"\nwith visible_progress(\"Run this request\"):\n writing_result = model.respond(writing_prompt, mode=\"auto\", max_new_tokens=128)\nshow_response(writing_result)\n"},{"cell_type": "markdown","id": "decision-intro","metadata": {},"source": "## 4. Try Decision JSON\n\nThe request explicitly asks for one of the supplied teams. JSON alone does not\nmean decision mode. The `choices` mapping below tells the scorer what A and B mean;\nit does **not** add choices to the prompt a second time.\n"},{"cell_type": "code","id": "decision-example","metadata": {},"execution_count": null,"outputs": [],"source": "import json\n\nchoices = {\"A\": \"Billing\", \"B\": \"Technical support\"}\nrequest = {\n \"context\": \"API key rejected.\",\n \"request\": \"Choose a team. A or B only.\",\n \"alternatives\": choices,\n}\ndecision_prompt = json.dumps(request, ensure_ascii=False, indent=2)\nprint(decision_prompt)\nwith visible_progress(\"Run this request\"):\n decision_result = model.respond(decision_prompt, choices=choices, mode=\"auto\")\nshow_response(decision_result)\n"},{"cell_type": "markdown","id": "exercise-intro","metadata": {},"source": "## 5. Change the instruction\n\nKeep the JSON and choices, but ask for an explanation. Run the cell below, then edit\nits request yourself. Selection **with an explanation** belongs to generation mode.\nRouting and answer quality can be wrong; the notebook shows what the model actually did.\n\nSupported decisions have 2–18 mapped choices and at most 2,048 tokens including\nthe chat wrapper. Overlength input is rejected rather than silently truncated.\nA decision route without valid choices is shown as unsupported, not rescued by a hidden fallback.\n"},{"cell_type": "code",1 unmodified line"metadata": {},"execution_count": null,"outputs": [],"source": "edited_request = dict(request)\nedited_request[\"request\"] = \"Choose a team and explain why this team should handle the problem.\"\nedited_prompt = json.dumps(edited_request, ensure_ascii=False, indent=2)\nwith visible_progress(\"Run this request\"):\n result = model.respond(edited_prompt, choices=choices, mode=\"auto\", max_new_tokens=128)\nshow_response(result)\n"},{"cell_type": "markdown",23 unmodified lines"thesystem": {"release": "0.1.0rc3","gpu_required": true,"private_staging": true,"bootstrap_finalized": true,"execution": "inference"}3 unmodified lines456789101112131415161718192021221 unmodified line2425262728293011 unmodified lines4243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697981 unmodified line1001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361 unmodified line13813914014114214314423 unmodified lines1681691701711721731743 unmodified lines"cell_type": "markdown","id": "title","metadata": {},"source": "# Try TheSystem — Probe-256\n\nTry automatic routing with four decision JSON layouts and four generation prompts.\nThen make a decision and ask the same model to explain it.\n\nThe frozen Qwen backbone feeds a classifier with one 256-unit hidden layer. There are no LoRA modules in this model. The selected checkpoint is seed 42, epoch 6. Both release models use the same selected diverse-42 `<FAST>` gate.\n"},{"cell_type": "markdown","id": "prerequisites","metadata": {},"source": "## Before you start\n\nSelect **Runtime → Change runtime type → latest runtime version → NVIDIA GPU**.\nUse Linux, Python 3.12 or 3.13 and native BF16 support. A **24 GB GPU may be tried**;\nthere is no minimum-memory cutoff. This capacity has not yet been validated for\nthese demos. Free T4 runtimes lack native BF16 support and are unsupported.\n\nBF16 weights alone use about 18 GB. Loading and requests need extra GPU memory,\nwhich depends on the prompt and response length. Setup reports total/free memory;\n**READY** confirms the software and GPU checks, not that the model will fit.\nKeep only one model loaded. Allow about 18 GB of disk space for the backbone plus caches.\n\nStart with a fresh runtime. This demo reuses Colab's PyTorch 2.14.x and NumPy. Setup installs only the inference\npackages it needs, without compiling CUDA extensions or running training checks.\nThe selected weights and prompt format are unchanged. Built-in PyTorch operations\ncan be slower and may give small numerical differences from the research kernels.\nUse notebook 03 for reproducing the published measurements.\n\nRun the cells in order. The notebook downloads the public model files automatically.\n"},{"cell_type": "markdown","id": "prepare-intro","metadata": {},"source": "## 1. Prepare runtime\n\nRun this cell to check the GPU, install missing inference packages, and verify\nthe downloaded release wheel.\nProgress and elapsed-time updates appear every 20 seconds; details are saved in\n`thesystem-prepare-runtime.log`.\n\nContinue when it says **READY**. A fresh Colab session normally needs no restart.\nIf this session already imported an older package, setup will explain how to\nrestart once and rerun the cell. No compiler setup or separate NumPy upgrade is needed.\n"},{"cell_type": "code",1 unmodified line"metadata": {"cellView": "form"},"source": "# @title Prepare runtime\nRUNTIME_READY = False\nimport hashlib, sys\nfrom urllib.request import urlopen\nfrom urllib.error import HTTPError, URLError\n\nPREPARE = {'repo_id': 'bqpro1/TheSystem', 'revision': 'd406079135fa83be43783116093bfb5b6ca593d2', 'sha256': '02313859f79b3b418298e36bbcbc6c525fa5f6bbfb0301ed7db84de60a5a657c'}\nprint(\"Prepare runtime: checking Python…\", flush=True)\nif sys.version_info[:2] not in ((3, 12), (3, 13)):\n raise RuntimeError(\"Use Python 3.12 or 3.13: Colab Runtime → Change runtime type → the latest runtime version.\")\nprint(\"Downloading the small, pinned setup helper (30-second timeout)…\", flush=True)\nurl = f\"https://raw.githubusercontent.com/{PREPARE['repo_id']}/{PREPARE['revision']}/notebooks/prepare_runtime.py\"\ntry:\n with urlopen(url, timeout=30) as response:\n helper = response.read()\nexcept HTTPError as error:\n raise RuntimeError(f\"Could not download the pinned public setup helper (HTTP {error.code}). \"\n \"Reopen the current notebook from GitHub and try again.\") from None\nexcept (URLError, TimeoutError) as error:\n raise RuntimeError(\"Setup helper download failed or timed out. Check the connection and rerun Prepare runtime.\") from None\nif hashlib.sha256(helper).hexdigest() != PREPARE[\"sha256\"]:\n raise RuntimeError(\"Setup helper checksum mismatch. Stop and obtain a fresh release notebook.\")\n_setup = {\"__name__\": \"thesystem_demo_setup\"}\nexec(compile(helper, \"prepare_runtime.py\", \"exec\"), _setup)\nvisible_progress = _setup[\"visible_progress\"]\ntorch = _setup[\"prepare_runtime\"](\"probe\")\n\nRUNTIME_READY = True","outputs": [],"execution_count": null},11 unmodified lines"outputs": [],"source": "if not globals().get(\"RUNTIME_READY\", False):\n raise RuntimeError(\"Run Prepare runtime until it reports READY before loading the model.\")\n\nfrom thesystem import load_model\nfrom thesystem.artifacts import resolve_model_resources\n\nif globals().get(\"model\") is not None:\n if getattr(model, \"variant\", None) != \"probe\":\n raise RuntimeError(\"A different model is already loaded. Restart the session before loading this model.\")\n print(\"Reusing the loaded model; continue to the examples.\")\nelse:\n with visible_progress(\"Download and load the selected model\"):\n RESOURCE_ROOT = resolve_model_resources(\"probe\")\n model = load_model(\"probe\", root=RESOURCE_ROOT, execution=\"inference\")\n print(\"Loaded the selected Probe-256 checkpoint with the shared <FAST> gate.\")\n"},{"cell_type": "markdown","id": "decision-intro","metadata": {},"source": "## 3. Decision mode\n\nTry four JSON layouts. Each asks for exactly one supplied answer. The API receives JSON as prompt text\nand a separate `choices` map matching the codes and labels in that text. Use 2–18 choices with consecutive\ncodes starting at A.\n\nThe training data for this release had no examples in the **Noul** JSON format (`type: \"noul\"`).\nThe next release will include Noul examples in training.\n\nEvery example uses `mode=\"auto\"`. **Answer** shows the mode the gate selected and the result.\nThe `expected_mode` label appears in **Metadata** for comparison, alongside response time\nand the `<FAST>` probability of choosing decision mode.\nEdit a case or instruction and rerun its cell. To inspect extra fields, enter `result` in a new cell.\n"},{"cell_type": "code","id": "display-response","metadata": {},"execution_count": null,"outputs": [],"source": "import json\nfrom contextlib import redirect_stdout\nfrom io import StringIO\nfrom time import perf_counter\n\ndef show_answer(result):\n print(f\"Selected mode: {result['mode']}\")\n if result[\"mode\"] == \"decision\":\n print(f\"Selected choice: {result['selected_code']} — {result['answer']}\")\n elif result[\"mode\"] == \"generation\":\n print(f\"Response: {result['answer']}\")\n else:\n print(\"The gate selected decision mode, which requires a choices mapping.\")\n if result.get(\"hit_limit\"):\n print(\"The generated response reached its token limit.\")\n\ndef run_example(label, request, *, expected_mode, choices=None, metadata=None):\n prompt = request if isinstance(request, str) else json.dumps(request, ensure_ascii=False, indent=2)\n started = perf_counter()\n # Capture progress so the answer leads the cell output.\n with redirect_stdout(StringIO()), visible_progress(label):\n result = model.respond(prompt, choices=choices, mode=\"auto\", max_new_tokens=128)\n elapsed = perf_counter() - started\n\n print(\"Answer\" if metadata is None else f\"\\n{label}\")\n show_answer(result)\n details = (\n f\"{label}\\n\"\n f\"<FAST> decision probability: {result['gate_probability']:.2%} (threshold: 50%)\\n\"\n f\"Expected mode: {expected_mode} · Response time: {elapsed:.1f} s\"\n )\n if metadata is None:\n print(f\"\\nMetadata\\n{details}\")\n else:\n metadata.append(details)\n return {key: value for key, value in result.items()\n if key not in {\"trace\", \"routing_trace\", \"generation_trace\"}}\n"},{"cell_type": "code","id": "decision-example","metadata": {},"execution_count": null,"outputs": [],"source": "team_choices = {\"A\": \"Billing\", \"B\": \"Technical support\"}\nteam_request = {\n \"context\": \"Billing handles invoices. Technical support handles API access. A customer's API key was rejected.\",\n \"request\": \"Which team should handle this ticket? Choose one of the listed teams.\",\n \"alternatives\": team_choices,\n}\nresult = run_example(\"Flat object with a choice map\", team_request, expected_mode=\"decision\", choices=team_choices)\n"},{"cell_type": "code","id": "decision-array","metadata": {},"execution_count": null,"outputs": [],"source": "priority_choices = {\"A\": \"Routine\", \"B\": \"Soon\", \"C\": \"Immediate\"}\npriority_request = {\n \"context\": \"A typo is Routine, a slow page is Soon, and a full outage is Immediate. The site is down for everyone.\",\n \"question\": \"What is the incident priority?\",\n \"options\": [{\"code\": code, \"label\": label} for code, label in priority_choices.items()],\n \"instruction\": \"Select one option and return only its code.\",\n}\nresult = run_example(\"Array of labeled options\", priority_request, expected_mode=\"decision\", choices=priority_choices)\n"},{"cell_type": "code","id": "decision-nested","metadata": {},"execution_count": null,"outputs": [],"source": "refund_choices = {\"A\": \"Eligible\", \"B\": \"Ineligible\"}\nrefund_request = {\n \"assessment_job\": {\n \"payload\": {\n \"evidence\": \"Refunds are allowed within 7 days. The customer purchased the item 4 days ago.\",\n \"query\": \"Is the customer eligible for a refund?\",\n },\n \"response_menu\": refund_choices,\n \"operation\": \"Make one selection and return only its answer code.\",\n },\n}\nresult = run_example(\"Nested assessment object\", refund_request, expected_mode=\"decision\", choices=refund_choices)\n"},{"cell_type": "code","id": "decision-question","metadata": {},"execution_count": null,"outputs": [],"source": "desk_choices = {\"A\": \"Finance\", \"B\": \"Engineering\", \"C\": \"General\"}\ndesk_request = {\n \"state\": \"Receipts go to Finance, bug reports to Engineering, and other documents to General. A bug report arrived.\",\n \"questions\": {\n \"destination\": {\n \"type\": \"choice\",\n \"instructions\": \"Which desk receives this document?\",\n \"criteria\": list(desk_choices.values()),\n },\n },\n \"requested_question\": \"destination\",\n \"candidate_codes\": desk_choices,\n \"answer_encoding\": \"Return only the code for the chosen desk.\",\n}\nresult = run_example(\"Named question with a separate code map\", desk_request, expected_mode=\"decision\", choices=desk_choices)\n"},{"cell_type": "markdown","id": "writing-intro","metadata": {},"source": "## 4. Generation mode\n\nThe first two prompts are plain text. The next two are JSON with writing instructions,\nincluding one with an `options` list of topics to explain. All four ask the model to produce prose.\n"},{"cell_type": "code",1 unmodified line"metadata": {},"execution_count": null,"outputs": [],"source": "writing_prompt = \"In two sentences, reply to Maya about her rejected API key and ask her to check if it is active.\"\nresult = run_example(\"Customer reply from plain text\", writing_prompt, expected_mode=\"generation\")\n"},{"cell_type": "code","id": "writing-plain-email","metadata": {},"execution_count": null,"outputs": [],"source": "email_prompt = \"Write a quick email to Sam saying I can attend the meeting tomorrow at 2 p.m.\"\nresult = run_example(\"Meeting confirmation from plain text\", email_prompt, expected_mode=\"generation\")\n"},{"cell_type": "code","id": "writing-json-ticket","metadata": {},"execution_count": null,"outputs": [],"source": "reply_request = {\n \"request\": \"Write a warm two-sentence reply to the customer.\",\n \"ticket\": {\"customer\": \"Maya\", \"issue\": \"The shipment is one day late.\"},\n \"include\": [\"an apology\", \"the next update will arrive tomorrow\"],\n}\nresult = run_example(\"Customer reply from JSON\", reply_request, expected_mode=\"generation\")\n"},{"cell_type": "code","id": "writing-json-options","metadata": {},"execution_count": null,"outputs": [],"source": "guide_request = {\n \"request\": \"Write a short onboarding note explaining when to use each support channel.\",\n \"audience\": \"New teammates\",\n \"options\": [\n {\"channel\": \"Chat\", \"use\": \"Quick questions during business hours\"},\n {\"channel\": \"Email\", \"use\": \"Requests that need attachments or a written record\"},\n ],\n}\nresult = run_example(\"Guide from JSON with an options list\", guide_request, expected_mode=\"generation\")\n"},{"cell_type": "markdown","id": "exercise-intro","metadata": {},"source": "## 5. Decide, then explain\n\nEach iteration revisits a case from section 3, then sends the chosen code and answer as a JSON record\nin a second request to the same model. That call asks Qwen to explain the supplied choice using the case\nfacts. The generated explanation may disagree with the selection.\n"},{"cell_type": "code",1 unmodified line"metadata": {},"execution_count": null,"outputs": [],"source": "cases = [(\"Support team\", team_request, team_choices), (\"Incident priority\", priority_request, priority_choices)]\nmetadata = []\nprint(\"Answer\")\nfor label, request, choices in cases:\n decision = run_example(label, request, expected_mode=\"decision\", choices=choices, metadata=metadata)\n if decision[\"mode\"] != \"decision\":\n print(\"Skipping the explanation because this request returned no selected choice.\")\n continue\n\n decision_record = {\n \"context\": request[\"context\"],\n \"selected_code\": decision[\"selected_code\"],\n \"selected_answer\": decision[\"answer\"],\n }\n explanation_request = {\n \"request\": (\n \"Write two sentences explaining the recorded decision using the case facts. \"\n \"If the facts conflict with the selected answer, describe the conflict.\"\n ),\n \"decision\": decision_record,\n }\n run_example(f\"{label} explanation\", explanation_request, expected_mode=\"generation\", metadata=metadata)\nprint(\"\\nMetadata\\n\" + \"\\n\\n\".join(metadata))\n"},{"cell_type": "markdown",23 unmodified lines"thesystem": {"release": "0.1.0rc3","gpu_required": true,"private_staging": false,"bootstrap_finalized": true,"execution": "inference"}
notebook.ipynb+63-15