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0
|
| 3 |
+
base_model: Qwen/Qwen2.5-7B-Instruct
|
| 4 |
+
tags:
|
| 5 |
+
- workflow-planning
|
| 6 |
+
- slm
|
| 7 |
+
- lora
|
| 8 |
+
- mlx
|
| 9 |
+
- apple-silicon
|
| 10 |
+
- policy-learning
|
| 11 |
+
- qwen2
|
| 12 |
+
- text-classification
|
| 13 |
+
- contrastive-alignment
|
| 14 |
+
library_name: mlx
|
| 15 |
+
pipeline_tag: text-generation
|
| 16 |
+
language:
|
| 17 |
+
- en
|
| 18 |
+
datasets:
|
| 19 |
+
- ssaraf1/slm-workflow-planner-policy-v2
|
| 20 |
+
- ssaraf1/slm-workflow-planner-alignment-v2
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
# SLM Workflow Planner 7B v2 β Contrastive Alignment LoRA Adapter
|
| 24 |
+
|
| 25 |
+
## Model Description
|
| 26 |
+
|
| 27 |
+
LoRA adapter for **Qwen/Qwen2.5-7B-Instruct** fine-tuned as a **workflow execution planner**.
|
| 28 |
+
This is the **v2 alignment model** β trained in two stages:
|
| 29 |
+
|
| 30 |
+
1. **Stage A**: Base policy training on 554K samples from 89 diverse workflow graphs (iter 800)
|
| 31 |
+
2. **Stage B**: Contrastive alignment on 20K curated samples with clean decision boundaries (iter 100)
|
| 32 |
+
|
| 33 |
+
The model makes real-time decisions about workflow transitions by analyzing state signals,
|
| 34 |
+
eligible nodes, and topology information.
|
| 35 |
+
|
| 36 |
+
### Decision Types
|
| 37 |
+
|
| 38 |
+
| Decision | Description |
|
| 39 |
+
|----------|-------------|
|
| 40 |
+
| **NEXT** | Proceed to the next sequential step |
|
| 41 |
+
| **RETRY** | Retry the current step (within budget) |
|
| 42 |
+
| **FORK** | Launch parallel execution branches |
|
| 43 |
+
| **JOIN** | Synchronize parallel branches |
|
| 44 |
+
| **META** | Escalate β anomaly detected, human intervention needed |
|
| 45 |
+
|
| 46 |
+
## Performance (76-scenario evaluation suite)
|
| 47 |
+
|
| 48 |
+
| Category | v2 SLM | GPT-4.1 | GPT-4o-mini | Base SLM |
|
| 49 |
+
|----------|--------|---------|-------------|----------|
|
| 50 |
+
| **NEXT** | 10/22 (45%) | 6/22 (27%) | 2/22 (9%) | 16/22 (73%) |
|
| 51 |
+
| **RETRY** | 7/12 (58%) | 11/12 (92%) | 12/12 (100%) | 3/12 (25%) |
|
| 52 |
+
| **FORK** | 13/14 (93%) | 14/14 (100%) | 14/14 (100%) | 1/14 (7%) |
|
| 53 |
+
| **JOIN** | 10/15 (67%) | 10/15 (67%) | 12/15 (80%) | 0/15 (0%) |
|
| 54 |
+
| **META** | 2/13 (15%) | 0/13 (0%) | 0/13 (0%) | 8/13 (62%) |
|
| 55 |
+
| **TOTAL** | **42/76 (55.3%)** | 41/76 (53.9%) | 40/76 (52.6%) | 28/76 (36.8%) |
|
| 56 |
+
|
| 57 |
+
### Key Results
|
| 58 |
+
- π **Outperforms GPT-4.1** (55.3% vs 53.9%) on structured workflow planning
|
| 59 |
+
- π **Only model that handles META** β GPT-4.1 and GPT-4o-mini score 0% on anomaly detection
|
| 60 |
+
- π₯ **FORK: 93%** β near-perfect parallel execution decisions
|
| 61 |
+
- π₯ **JOIN: 67%** β first model to reliably synchronize parallel branches
|
| 62 |
+
- β‘ **4x faster inference** than base model, runs locally on Apple Silicon
|
| 63 |
+
|
| 64 |
+
## Training Details
|
| 65 |
+
|
| 66 |
+
### Two-Stage Training
|
| 67 |
+
|
| 68 |
+
**Stage A: Base Policy (iter 800)**
|
| 69 |
+
- Dataset: 554K instruction pairs from 89 workflow graphs
|
| 70 |
+
- 8 structural families (linear, retry, fork-join, escalation, etc.)
|
| 71 |
+
- Balanced decision distribution: NEXT 36%, JOIN 27%, META 13%, FORK 12%, RETRY 12%
|
| 72 |
+
|
| 73 |
+
**Stage B: Contrastive Alignment (iter 100)**
|
| 74 |
+
- Dataset: 20K curated samples with clean decision boundaries
|
| 75 |
+
- Contrastive pairs: FORK positives + hard FORK negatives (NEXT with forkable but blocked)
|
| 76 |
+
- JOIN positives + hard JOIN negatives (NEXT with join_ready but no parallel)
|
| 77 |
+
- Clean RETRY and META samples
|
| 78 |
+
- Proportional representation across all decision types
|
| 79 |
+
|
| 80 |
+
### LoRA Configuration
|
| 81 |
+
| Parameter | Value |
|
| 82 |
+
|-----------|-------|
|
| 83 |
+
| Rank | 16 |
|
| 84 |
+
| Alpha (scale) | 32 (2.0x) |
|
| 85 |
+
| Dropout | 0.02 |
|
| 86 |
+
| Target layers | Last 28 of 32 |
|
| 87 |
+
| Target modules | q_proj, k_proj, v_proj, o_proj |
|
| 88 |
+
|
| 89 |
+
### Training Configuration
|
| 90 |
+
| Parameter | Value |
|
| 91 |
+
|-----------|-------|
|
| 92 |
+
| Framework | MLX (Apple Silicon native) |
|
| 93 |
+
| Hardware | Apple M4 Pro, 48GB unified memory |
|
| 94 |
+
| Stage A iters | 800 |
|
| 95 |
+
| Stage B iters | 100 |
|
| 96 |
+
| Batch size | 4 |
|
| 97 |
+
| Learning rate | 3e-5 (alignment stage) |
|
| 98 |
+
| Sequence length | 512 |
|
| 99 |
+
| Prompt masking | Yes (loss only on assistant tokens) |
|
| 100 |
+
|
| 101 |
+
### Training Curve (Alignment Stage)
|
| 102 |
+
| Iteration | Val Loss | Train Loss |
|
| 103 |
+
|-----------|----------|------------|
|
| 104 |
+
| 1 (start) | 14.536 | β |
|
| 105 |
+
| 50 | 0.134 | 0.273 |
|
| 106 |
+
| 100 (final) | 0.099 | 0.135 |
|
| 107 |
+
|
| 108 |
+
## Usage
|
| 109 |
+
|
| 110 |
+
### With MLX (Apple Silicon)
|
| 111 |
+
|
| 112 |
+
```python
|
| 113 |
+
from mlx_lm import load, generate
|
| 114 |
+
from mlx_lm.sample_utils import make_sampler
|
| 115 |
+
|
| 116 |
+
model, tokenizer = load(
|
| 117 |
+
"Qwen/Qwen2.5-7B-Instruct",
|
| 118 |
+
adapter_path="ssaraf1/slm-workflow-planner-7b-v2"
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
messages = [
|
| 122 |
+
{"role": "system", "content": "You are a workflow planner. Given the current workflow state, eligible nodes, and topology information, classify the decision type. Respond with exactly one of: NEXT, RETRY, FORK, JOIN, META"},
|
| 123 |
+
{"role": "user", "content": "Current node: TRIAGE_AND_ASSIGN (AGENT)\nOutcome: assigned\n\nState:\n goal_progress=0.15\n parallel_active=0\n resource_pressure=0.1\n\nEligible nodes:\n 1. VERIFY_POLICY (SYSTEM) β produces: policy_status\n 2. FRAUD_SCREENING (SYSTEM) β produces: fraud_score\n 3. DAMAGE_ASSESSMENT (AGENT) β produces: damage_report\n\nForkable sets: [{VERIFY_POLICY, FRAUD_SCREENING, DAMAGE_ASSESSMENT}]\nJoin-ready: []\n\nWhat decision type?"}
|
| 124 |
+
]
|
| 125 |
+
|
| 126 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 127 |
+
sampler = make_sampler(temp=0.0)
|
| 128 |
+
response = generate(model, tokenizer, prompt=prompt, max_tokens=10, sampler=sampler)
|
| 129 |
+
print(response) # Expected: FORK
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
## What Makes This Model Special
|
| 133 |
+
|
| 134 |
+
### Contrastive Alignment
|
| 135 |
+
Unlike naive fine-tuning, this model was trained with **contrastive pairs** that teach
|
| 136 |
+
policy boundaries, not just pattern matching:
|
| 137 |
+
|
| 138 |
+
| Scenario | Topology says | State says | Model learns |
|
| 139 |
+
|----------|--------------|------------|--------------|
|
| 140 |
+
| Forkable + low pressure | FORK | Go parallel | **FORK** β
|
|
| 141 |
+
| Forkable + high pressure | FORK | Don't parallelize | **NEXT** β
|
|
| 142 |
+
| Join-ready + parallel active | JOIN | Merge now | **JOIN** β
|
|
| 143 |
+
| Join-ready + no parallel | JOIN | Not ready | **NEXT** β
|
|
| 144 |
+
|
| 145 |
+
### Policy Learning, Not Path Memorization
|
| 146 |
+
The model learns `decision = f(state signals, topology, actors)`, not domain-specific
|
| 147 |
+
workflow paths. This enables generalization to unseen workflow structures.
|
| 148 |
+
|
| 149 |
+
## Files
|
| 150 |
+
|
| 151 |
+
- `adapters.safetensors` β LoRA adapter weights (base iter 800 + alignment iter 100)
|
| 152 |
+
- `adapter_config.json` β LoRA configuration for MLX
|
| 153 |
+
|
| 154 |
+
## Citation
|
| 155 |
+
|
| 156 |
+
Part of the **Agentic Factory** project β building autonomous workflow orchestration
|
| 157 |
+
with SLM-powered planning on Apple Silicon.
|