Spaces:
Running on Zero
Running on Zero
atakan commited on
Commit ·
30f040e
1
Parent(s): d08774c
feat: Add model fusion script and Ollama Modelfile configuration
Browse files- .gitignore +1 -0
- Modelfile +19 -0
- scripts/fuse_model.py +60 -0
.gitignore
CHANGED
|
@@ -22,6 +22,7 @@ data/
|
|
| 22 |
# Model checkpoints and fine-tuned weights
|
| 23 |
adapters/
|
| 24 |
checkpoints/
|
|
|
|
| 25 |
|
| 26 |
# Generated simulation outputs & plot images
|
| 27 |
outputs/
|
|
|
|
| 22 |
# Model checkpoints and fine-tuned weights
|
| 23 |
adapters/
|
| 24 |
checkpoints/
|
| 25 |
+
models/
|
| 26 |
|
| 27 |
# Generated simulation outputs & plot images
|
| 28 |
outputs/
|
Modelfile
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ControlAI Ollama Model Template
|
| 2 |
+
FROM qwen2.5:3b
|
| 3 |
+
|
| 4 |
+
# Set deterministic temperature for control engineering & exact math
|
| 5 |
+
PARAMETER temperature 0.2
|
| 6 |
+
PARAMETER top_p 0.95
|
| 7 |
+
PARAMETER stop "<|im_end|>"
|
| 8 |
+
PARAMETER stop "<|endoftext|>"
|
| 9 |
+
|
| 10 |
+
# Set the safety-critical system prompt
|
| 11 |
+
SYSTEM """You are ControlAI, a premier AI research scientist and expert engineering agent specialized in control systems engineering, applied mathematics, robotics, and dynamical systems.
|
| 12 |
+
|
| 13 |
+
### 4-Stage Mathematical Reasoning & Proof Standard:
|
| 14 |
+
When answering theoretical principles, derivations, proofs, comparisons, or limitation questions:
|
| 15 |
+
1. State the state-space equations, signal spaces, and underlying assumptions.
|
| 16 |
+
2. State the governing theorem with exact mathematical rigor (PBH rank test, Doyle 1978 LQG robustness counterexample, Lyapunov Invariance).
|
| 17 |
+
3. Provide the full closed-form relationships in pure LaTeX.
|
| 18 |
+
4. Explicitly state engineering breakdown conditions and conservation trade-offs (Bode sensitivity integral).
|
| 19 |
+
"""
|
scripts/fuse_model.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Merge/Fuse ControlAI LoRA fine-tuned adapter into base model to produce a standalone model."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import subprocess
|
| 8 |
+
import sys
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def main() -> None:
|
| 15 |
+
parser = argparse.ArgumentParser(description="Fuse ControlAI LoRA adapter into base model")
|
| 16 |
+
parser.add_argument(
|
| 17 |
+
"--model",
|
| 18 |
+
type=str,
|
| 19 |
+
default="mlx-community/Qwen3-4B-Instruct-2507-4bit",
|
| 20 |
+
help="Base model path or Hugging Face repo ID",
|
| 21 |
+
)
|
| 22 |
+
parser.add_argument(
|
| 23 |
+
"--adapter-path",
|
| 24 |
+
type=str,
|
| 25 |
+
default="adapters/controlai_qwen3_4b_sft_v2",
|
| 26 |
+
help="Path to trained LoRA adapter",
|
| 27 |
+
)
|
| 28 |
+
parser.add_argument(
|
| 29 |
+
"--save-path",
|
| 30 |
+
type=str,
|
| 31 |
+
default="models/controlai_fused",
|
| 32 |
+
help="Target folder for standalone merged model",
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
args = parser.parse_args()
|
| 36 |
+
|
| 37 |
+
print(f"Fusing LoRA adapter from {args.adapter_path} into {args.model}...")
|
| 38 |
+
cmd = [
|
| 39 |
+
sys.executable,
|
| 40 |
+
"-m",
|
| 41 |
+
"mlx_lm",
|
| 42 |
+
"fuse",
|
| 43 |
+
"--model",
|
| 44 |
+
args.model,
|
| 45 |
+
"--adapter-path",
|
| 46 |
+
args.adapter_path,
|
| 47 |
+
"--save-path",
|
| 48 |
+
args.save_path,
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
res = subprocess.run(cmd, cwd=PROJECT_ROOT)
|
| 52 |
+
if res.returncode == 0:
|
| 53 |
+
print(f"\nModel successfully fused into standalone checkpoint at: {args.save_path}")
|
| 54 |
+
else:
|
| 55 |
+
print(f"\nError during fusion (exit code {res.returncode})")
|
| 56 |
+
sys.exit(res.returncode)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
main()
|