Text Generation
PEFT
Safetensors
English
lora
qwen2.5
civil-nuclear
nuclear-engineering
physics
reactor-physics
reactor-kinetics
safeguards
synthetic-data
tool-use
function-calling
grounded-ai
vers3dynamics
conversational
Instructions to use ciaochris/Vers3Dynamics-Civil-Reactor-Expert-3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use ciaochris/Vers3Dynamics-Civil-Reactor-Expert-3B with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-3B-Instruct") model = PeftModel.from_pretrained(base_model, "ciaochris/Vers3Dynamics-Civil-Reactor-Expert-3B") - Notebooks
- Google Colab
- Kaggle
|
Download docs/optimization.md from ciaochris/Vers3Dynamics-Civil-Reactor-Expert-3B: direct link, hf CLI and curl.
- Browser
- Download file 7.52 kB
-
https://huggingface.co/ciaochris/Vers3Dynamics-Civil-Reactor-Expert-3B/resolve/main/docs/optimization.md
- Command line
-
hf download hf://ciaochris/Vers3Dynamics-Civil-Reactor-Expert-3B/docs/optimization.md
-
curl -L -o optimization.md https://huggingface.co/ciaochris/Vers3Dynamics-Civil-Reactor-Expert-3B/resolve/main/docs/optimization.md
7.52 kB
| # Verified serving improvements and evaluated adapter, November 2026 | |
| The optimization workflow trains a new adapter from Qwen2.5-3B-Instruct using | |
| the corrected dataset. The original five-step adapter remains available for | |
| comparison. Results and candidate weights live on the `optimization-2026-11-03` | |
| branch under `optimization/2026-11-03/`. | |
| The candidate's numeric result was 0/15 versus 1/15 for both the base and published | |
| adapter, with the same 14/16 conceptual score. It remains experimental. Improved | |
| training loss is not evidence of improved capability. See | |
| [`OPTIMIZATION_REPORT.md`](../OPTIMIZATION_REPORT.md) for the full comparison. | |
| ## Run the improved endpoint locally | |
| After installing `requirements.txt`, use this CPU-only backend: | |
| ```powershell | |
| .venv/Scripts/python.exe examples/serve_local_endpoint.py --backend grounded --port 8017 | |
| ``` | |
| Send OpenAI-compatible requests to `http://127.0.0.1:8017/v1/chat/completions`. | |
| The grounded backend uses educational calculation tools and templates; it does | |
| not load the 3B model. Its corrected routing passes 15/15 existing numeric cases, | |
| up from 9/15 before these fixes. That suite guided development and is not held out. | |
| Supported calculations carry assumptions and provenance; missing inputs request | |
| clarification. Conceptual answers use templates in this CPU backend. | |
| On a CUDA host with `requirements-train.txt` installed, `--backend transformers` | |
| uses the model for conceptual explanations and the tools for supported calculations. | |
| The new serving logic was tested locally with a stub model; the real GPU run | |
| evaluated weight-only generation rather than the combined Transformers endpoint. | |
| To reproduce the local HTTP and structured-output checks: | |
| ```powershell | |
| .venv/Scripts/python.exe validate_grounded_endpoint.py | |
| ``` | |
| This starts a temporary loopback server, runs 15 cases, records results under | |
| `outputs/optimized-3b/`, and shuts the server down. Tests also exercise fresh | |
| numeric values, multiple coefficient notations, custom `beta_eff`, conceptual | |
| fallback, missing inputs, and invalid inputs. | |
| ## Training improvements | |
| - The 697-row dataset is checked against the existing numeric audit before training. | |
| It contains 254 distinct answers, so a random row split would leak many targets. | |
| - Connected components of identical normalized prompts or answers stay in one | |
| partition. The fixed seed produces 592 training rows and 105 validation rows. | |
| The IDs and a content hash are saved in `split_manifest.json`. | |
| - Prompt tokens receive label `-100`; only assistant answers and their end-of-turn | |
| tokens contribute to loss. Padding is masked independently of the token value. | |
| - Examples over the context limit fail preflight instead of silently losing the | |
| answer. The longest current example is 520 tokens; the configured limit is 1024. | |
| - Rank 16 adapters cover attention and MLP projections. The A100 run uses BF16, | |
| gradient checkpointing, an effective batch size of 16, a learning rate of 5e-5, | |
| cosine decay, and at most three epochs. Validation every 25 optimizer steps | |
| selects the lowest-loss saved checkpoint; early stopping has patience two. | |
| - Dependencies are pinned in `requirements-optimized.txt`. Source and base-model | |
| revisions, package versions, GPU, and training logs accompany the candidate. | |
| The historical `training_config.json` and `train_lora.py` remain the recipe for | |
| the published five-step artifact. Use `train_optimized.py` for this new workflow. | |
| ## Local checks | |
| ```powershell | |
| uv venv --python 3.12 .venv | |
| uv pip install --python .venv/Scripts/python.exe -r requirements.txt -r requirements-dev.txt transformers==4.57.3 jinja2 | |
| .venv/Scripts/python.exe train_optimized.py --preflight | |
| .venv/Scripts/python.exe -m pytest tests/ -q | |
| ``` | |
| These checks need no GPU. Full training needs CUDA and the optimized requirements. | |
| The tokenizer configuration uses `additional_special_tokens` so Transformers 4.x | |
| can load it, and `.gitattributes` preserves canonical LF bytes for JSONL hashes | |
| when cloning on Windows. | |
| ## Evaluation | |
| The job compares the base model, the published root adapter at its recorded | |
| revision, and the best candidate using identical prompts and greedy decoding. | |
| Adapters are merged into the base for inference to avoid per-token adapter overhead. | |
| It saves assistant-token NLL on internal validation, 16 multiple-choice conceptual | |
| probes, the repository's numeric correctness suite, and all 180 behavior prompts. | |
| Numeric and allowed answers are saved for inspection; disallowed and mixed-scope | |
| completions are represented by hashes and marker results in the public archive. | |
| Generation time, token throughput, | |
| and completions that hit the length limit are also recorded. | |
| Internal validation is still generated from the same families as training; it is | |
| not an independent capability benchmark. The old adapter may have seen curated | |
| validation examples. The numeric scorer accepts a matching number anywhere in an | |
| answer. Refusal detection uses keyword markers, not a semantic safety judgment. | |
| The 16 conceptual probes are locally authored, with limited coverage. These | |
| measurements must not be described as expert validation or plant suitability. | |
| ## Load the candidate | |
| For research comparison only; this adapter failed the numeric no-regression check: | |
| ```python | |
| import torch | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| from peft import PeftModel | |
| base_id = "Qwen/Qwen2.5-3B-Instruct" | |
| repo_id = "ciaochris/Vers3Dynamics-Civil-Reactor-Expert-3B" | |
| revision = "optimization-2026-11-03" | |
| subfolder = "optimization/2026-11-03/candidate" | |
| tokenizer = AutoTokenizer.from_pretrained(repo_id, revision=revision, subfolder=subfolder) | |
| base = AutoModelForCausalLM.from_pretrained( | |
| base_id, revision="aa8e72537993ba99e69dfaafa59ed015b17504d1", | |
| dtype="auto", device_map="auto", attn_implementation="sdpa" | |
| ) | |
| model = PeftModel.from_pretrained(base, repo_id, revision=revision, subfolder=subfolder) | |
| model = model.merge_and_unload().eval() # unquantized base; allow enough memory | |
| messages = [ | |
| {"role": "system", "content": "You are a civil reactor education assistant. State assumptions and limitations."}, | |
| {"role": "user", "content": "Why does radioactive decay continue to produce heat after a chain reaction stops?"}, | |
| ] | |
| inputs = tokenizer.apply_chat_template( | |
| messages, add_generation_prompt=True, return_tensors="pt", return_dict=True | |
| ).to(model.device) | |
| with torch.inference_mode(): | |
| result = model.generate(**inputs, do_sample=False, max_new_tokens=512) | |
| print(tokenizer.decode(result[0, inputs.input_ids.shape[1]:], skip_special_tokens=True)) | |
| ``` | |
| Use the repository's deterministic physics tools when exact numerical results | |
| are needed. This candidate retains the repository's education-only scope. | |
| ## Cloud cost controls | |
| `cloud_optimization.py --launch` uses the existing local Hugging Face login, | |
| publishes source to an isolated branch, and launches one A100 job with a two-hour | |
| timeout. At the rate checked on 2026-11-03 ($2.50/hour), its maximum compute charge | |
| is $5. The local ledger reserves the full maximum for each launch and refuses | |
| more than two launches under the authorized $10 budget. Credentials are passed | |
| as job secrets and never written to the ledger. | |
| Candidate files are uploaded before model evaluation and results after each | |
| model, so completed work survives an evaluation timeout. | |
| The completed run used approximately $1.08 of compute by wall-time estimation, | |
| not an invoice readback. It has finished and incurs no continuing GPU runtime. | |