Text Generation
PEFT
Safetensors
English
astrophysics
orbital-mechanics
cosmology
celestial-mechanics
lora
vigyan-ai
conversational
Instructions to use shreyansh12183/olmo2-7b-astro-logic with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use shreyansh12183/olmo2-7b-astro-logic with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("allenai/OLMo-2-1124-7B-Instruct") model = PeftModel.from_pretrained(base_model, "shreyansh12183/olmo2-7b-astro-logic") - Notebooks
- Google Colab
- Kaggle
fix(gradio): use rock-solid ChatInterface to eliminate UI validation errors
Browse files
colab_demo_olmo2_astro_logic.ipynb
CHANGED
|
@@ -8,17 +8,18 @@
|
|
| 8 |
"### Interactive Colab GPU Demo with Gradio (First-Gen Domain Foundation)\n",
|
| 9 |
"\n",
|
| 10 |
"**Architect & Creator:** Shreyansh Singh \u00b7 [ExperimentLab](https://github.com/shreyansh001boy-tech) \u00b7 [Hugging Face Repository](https://huggingface.co/shreyansh12183/olmo2-7b-astro-logic) \n",
|
|
|
|
| 11 |
"**Certified Benchmark:** `Certified Astrophysical Physics & Formal Proofs | General Relativity & Symbolic Logic` \n",
|
| 12 |
-
"**
|
| 13 |
"**License:** CC BY-NC 4.0 (Non-Commercial Sovereign License)\n",
|
| 14 |
"\n",
|
| 15 |
"---\n",
|
| 16 |
"\n",
|
| 17 |
"### \ud83d\ude80 Running This Demo on Google Colab:\n",
|
| 18 |
-
"1. Ensure
|
| 19 |
-
"2. Run **Cell 1** to install
|
| 20 |
-
"3. Run **Cell 2** to load
|
| 21 |
-
"4. Run **Cell 3** to launch the interactive Gradio web
|
| 22 |
"\n"
|
| 23 |
]
|
| 24 |
},
|
|
@@ -28,7 +29,7 @@
|
|
| 28 |
"execution_count": null,
|
| 29 |
"outputs": [],
|
| 30 |
"source": [
|
| 31 |
-
"# Cell 1: Install Required Libraries\n!pip install -q torch transformers bitsandbytes peft accelerate
|
| 32 |
]
|
| 33 |
},
|
| 34 |
{
|
|
@@ -37,7 +38,7 @@
|
|
| 37 |
"execution_count": null,
|
| 38 |
"outputs": [],
|
| 39 |
"source": [
|
| 40 |
-
"# Cell 2: Load
|
| 41 |
]
|
| 42 |
},
|
| 43 |
{
|
|
@@ -46,7 +47,7 @@
|
|
| 46 |
"execution_count": null,
|
| 47 |
"outputs": [],
|
| 48 |
"source": [
|
| 49 |
-
"# Cell 3: Launch Live Gradio Web Interface\nimport gradio as gr\n\nSYSTEM_PROMPT = \"You are OLMo-2 7B Astro Logic, an astrophysics and formal symbolic reasoning foundation model architected and fine-tuned by Shreyansh Singh (ExperimentLab). Solve complex celestial mechanics, general relativistic field equations, stellar nucleosynthesis problems, and rigorous formal symbolic logic derivations.\"\nEXAMPLES = [\"Derive the Schwarzschild metric geodesic equations and calculate the perihelion precession of Mercury.\", \"Explain the proton-proton chain vs CNO cycle in stellar nucleosynthesis and derive the Gamow peak energy window.\", \"Formulate the cosmological Friedmann equations from the FLRW metric and solve for a matter-dominated flat universe.\", \"Provide a formal symbolic natural deduction proof for the law of excluded middle in propositional logic.\"]\n\ndef
|
| 50 |
]
|
| 51 |
}
|
| 52 |
],
|
|
|
|
| 8 |
"### Interactive Colab GPU Demo with Gradio (First-Gen Domain Foundation)\n",
|
| 9 |
"\n",
|
| 10 |
"**Architect & Creator:** Shreyansh Singh \u00b7 [ExperimentLab](https://github.com/shreyansh001boy-tech) \u00b7 [Hugging Face Repository](https://huggingface.co/shreyansh12183/olmo2-7b-astro-logic) \n",
|
| 11 |
+
"**Architecture Lineage:** `Generation 1 \u00b7 Domain Specialist` \n",
|
| 12 |
"**Certified Benchmark:** `Certified Astrophysical Physics & Formal Proofs | General Relativity & Symbolic Logic` \n",
|
| 13 |
+
"**Model Identifier:** [`shreyansh12183/olmo2-7b-astro-logic`](https://huggingface.co/shreyansh12183/olmo2-7b-astro-logic) \n",
|
| 14 |
"**License:** CC BY-NC 4.0 (Non-Commercial Sovereign License)\n",
|
| 15 |
"\n",
|
| 16 |
"---\n",
|
| 17 |
"\n",
|
| 18 |
"### \ud83d\ude80 Running This Demo on Google Colab:\n",
|
| 19 |
+
"1. Ensure runtime is set to **T4 GPU** (`Runtime -> Change runtime type -> T4 GPU`).\n",
|
| 20 |
+
"2. Run **Cell 1** to install required libraries (`transformers`, `bitsandbytes`, `peft`, `gradio`).\n",
|
| 21 |
+
"3. Run **Cell 2** to load model weights in 4-bit NF4 into Colab GPU VRAM.\n",
|
| 22 |
+
"4. Run **Cell 3** to launch the interactive Gradio web app and receive your public `https://*.gradio.live` link!\n",
|
| 23 |
"\n"
|
| 24 |
]
|
| 25 |
},
|
|
|
|
| 29 |
"execution_count": null,
|
| 30 |
"outputs": [],
|
| 31 |
"source": [
|
| 32 |
+
"# Cell 1: Install Required Libraries\n!pip install -q \"gradio>=4.44.1\" torch transformers bitsandbytes peft accelerate\nprint('\u2713 Dependencies installed successfully!')\n"
|
| 33 |
]
|
| 34 |
},
|
| 35 |
{
|
|
|
|
| 38 |
"execution_count": null,
|
| 39 |
"outputs": [],
|
| 40 |
"source": [
|
| 41 |
+
"# Cell 2: Load Base Model & LoRA Adapter in 4-bit NF4\nimport torch\nfrom transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TextIteratorStreamer\nfrom peft import PeftModel\nimport threading\n\nBASE_ID = \"allenai/OLMo-2-1124-7B-Instruct\"\nADAPTER_ID = \"shreyansh12183/olmo2-7b-astro-logic\"\n\nprint(f\"Loading Base Foundation: {BASE_ID} in 4-bit NF4...\")\nbnb_config = BitsAndBytesConfig(\n load_in_4bit=True,\n bnb_4bit_quant_type=\"nf4\",\n bnb_4bit_compute_dtype=torch.float16,\n bnb_4bit_use_double_quant=True\n)\n\ntokenizer = AutoTokenizer.from_pretrained(BASE_ID, trust_remote_code=True)\nif tokenizer.pad_token is None:\n tokenizer.pad_token = tokenizer.eos_token\n\nbase_model = AutoModelForCausalLM.from_pretrained(\n BASE_ID,\n quantization_config=bnb_config,\n device_map=\"auto\",\n torch_dtype=torch.float16,\n trust_remote_code=True\n)\n\nprint(f\"Attaching Fine-Tuned LoRA Adapter: {ADAPTER_ID}...\")\nmodel = PeftModel.from_pretrained(base_model, ADAPTER_ID)\nmodel.eval()\nprint(f\"\u2713 {ADAPTER_ID} successfully loaded in Colab GPU VRAM!\")\n"
|
| 42 |
]
|
| 43 |
},
|
| 44 |
{
|
|
|
|
| 47 |
"execution_count": null,
|
| 48 |
"outputs": [],
|
| 49 |
"source": [
|
| 50 |
+
"# Cell 3: Launch Live Gradio Web Interface (Rock-Solid ChatInterface)\nimport gradio as gr\nimport threading\nfrom transformers import TextIteratorStreamer\n\nSYSTEM_PROMPT = \"You are OLMo-2 7B Astro Logic, an astrophysics and formal symbolic reasoning foundation model architected and fine-tuned by Shreyansh Singh (ExperimentLab). Solve complex celestial mechanics, general relativistic field equations, stellar nucleosynthesis problems, and rigorous formal symbolic logic derivations.\"\nEXAMPLES = [\"Derive the Schwarzschild metric geodesic equations and calculate the perihelion precession of Mercury.\", \"Explain the proton-proton chain vs CNO cycle in stellar nucleosynthesis and derive the Gamow peak energy window.\", \"Formulate the cosmological Friedmann equations from the FLRW metric and solve for a matter-dominated flat universe.\", \"Provide a formal symbolic natural deduction proof for the law of excluded middle in propositional logic.\"]\nTITLE = \"\\ud83d\\udd2d OLMo-2 7B Astro Logic Specialist\"\nDESCRIPTION = \"**Generation:** `Generation 1 \\u00b7 Domain Specialist` \\u00b7 **Model:** [`shreyansh12183/olmo2-7b-astro-logic`](https://huggingface.co/shreyansh12183/olmo2-7b-astro-logic) \\u00b7 **Certified:** `Certified Astrophysical Physics & Formal Proofs | General Relativity & Symbolic Logic`\"\n\ndef predict(message, history):\n messages = [{\"role\": \"system\", \"content\": SYSTEM_PROMPT}]\n for item in history:\n if isinstance(item, dict):\n role = item.get(\"role\", \"user\")\n content = item.get(\"content\", \"\")\n if content:\n messages.append({\"role\": role, \"content\": content})\n elif isinstance(item, (list, tuple)) and len(item) == 2:\n u_msg, a_msg = item[0], item[1]\n if u_msg:\n messages.append({\"role\": \"user\", \"content\": str(u_msg)})\n if a_msg:\n messages.append({\"role\": \"assistant\", \"content\": str(a_msg)})\n messages.append({\"role\": \"user\", \"content\": message})\n \n prompt_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)\n inputs = tokenizer(prompt_text, return_tensors=\"pt\").to(model.device)\n \n streamer = TextIteratorStreamer(tokenizer, timeout=60.0, skip_prompt=True, skip_special_tokens=True)\n gen_kwargs = dict(\n input_ids=inputs.input_ids,\n attention_mask=inputs.attention_mask,\n streamer=streamer,\n max_new_tokens=1024,\n temperature=0.3,\n top_p=0.9,\n repetition_penalty=1.1,\n do_sample=True\n )\n thread = threading.Thread(target=model.generate, kwargs=gen_kwargs)\n thread.start()\n \n partial_text = \"\"\n for new_text in streamer:\n partial_text += new_text\n yield partial_text\n\ndemo = gr.ChatInterface(\n fn=predict,\n title=TITLE,\n description=DESCRIPTION,\n examples=EXAMPLES,\n)\n\nprint(\"\\n\" + \"=\"*75)\nprint(\"\ud83d\ude80 Launching Gradio Web App with Public Share Link...\")\nprint(\"=\"*75 + \"\\n\")\ndemo.launch(share=True)\n"
|
| 51 |
]
|
| 52 |
}
|
| 53 |
],
|