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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.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 |
+
- fork-suppression
|
| 15 |
+
library_name: mlx
|
| 16 |
+
pipeline_tag: text-generation
|
| 17 |
+
language:
|
| 18 |
+
- en
|
| 19 |
+
datasets:
|
| 20 |
+
- ssaraf1/slm-workflow-planner-policy-v2
|
| 21 |
+
- ssaraf1/slm-workflow-planner-alignment-v2
|
| 22 |
+
---
|
| 23 |
+
|
| 24 |
+
# SLM Workflow Planner 7B v3 β Fork-Suppression Alignment (Best Overall)
|
| 25 |
+
|
| 26 |
+
## Model Description
|
| 27 |
+
|
| 28 |
+
LoRA adapter for **Qwen/Qwen2.5-7B-Instruct** fine-tuned as a **workflow execution planner**.
|
| 29 |
+
This is the **v3 model** β the best-performing checkpoint across all training phases, trained in three stages:
|
| 30 |
+
|
| 31 |
+
1. **Stage A**: Base policy training on 554K samples from 89 diverse workflow graphs (iter 800)
|
| 32 |
+
2. **Stage B**: Contrastive alignment on 20K curated samples with clean decision boundaries (iter 100)
|
| 33 |
+
3. **Stage C**: Fork-suppression alignment on 4.6K targeted samples to fix FORK over-triggering (iter 200)
|
| 34 |
+
|
| 35 |
+
The model makes real-time decisions about workflow transitions by analyzing state signals,
|
| 36 |
+
eligible nodes, and topology information.
|
| 37 |
+
|
| 38 |
+
### Decision Types
|
| 39 |
+
|
| 40 |
+
| Decision | Description |
|
| 41 |
+
|----------|-------------|
|
| 42 |
+
| **NEXT** | Proceed to the next sequential step |
|
| 43 |
+
| **RETRY** | Retry the current step (within budget) |
|
| 44 |
+
| **FORK** | Launch parallel execution branches |
|
| 45 |
+
| **JOIN** | Synchronize parallel branches |
|
| 46 |
+
| **META** | Escalate β anomaly detected, human intervention needed |
|
| 47 |
+
|
| 48 |
+
## Performance (76-scenario evaluation suite)
|
| 49 |
+
|
| 50 |
+
| Category | **v3 SLM** | v2 SLM | GPT-4.1 | GPT-4o-mini | Base SLM |
|
| 51 |
+
|----------|-----------|--------|---------|-------------|----------|
|
| 52 |
+
| **NEXT** | **15/22 (68%)** | 8/22 (36%) | 6/22 (27%) | 2/22 (9%) | 16/22 (73%) |
|
| 53 |
+
| **RETRY** | **12/12 (100%)** | 7/12 (58%) | 11/12 (92%) | 12/12 (100%) | 3/12 (25%) |
|
| 54 |
+
| **FORK** | **12/14 (86%)** | 14/15 (93%) | 14/14 (100%) | 14/14 (100%) | 1/14 (7%) |
|
| 55 |
+
| **JOIN** | **6/15 (40%)** | 10/15 (67%) | 10/15 (67%) | 12/15 (80%) | 0/15 (0%) |
|
| 56 |
+
| **META** | **0/13 (0%)** | 3/12 (25%) | 0/13 (0%) | 0/13 (0%) | 8/13 (62%) |
|
| 57 |
+
| **TOTAL** | **45/76 (59.2%)** | 42/76 (55.3%) | 41/76 (53.9%) | 40/76 (52.6%) | 28/76 (36.8%) |
|
| 58 |
+
|
| 59 |
+
### Key Results
|
| 60 |
+
- π **Best overall accuracy: 59.2%** β outperforms all previous versions and GPT-4.1
|
| 61 |
+
- π₯ **RETRY: 100%** β perfect retry handling (was 58% in v2)
|
| 62 |
+
- π₯ **FORK: 86%** β strong parallel execution decisions with correct suppression
|
| 63 |
+
- π₯ **NEXT: 68%** β massive improvement over v2 (36%) without collapse to NEXT
|
| 64 |
+
- β‘ **Balanced policy** β the only checkpoint that achieves strong NEXT + RETRY + FORK simultaneously
|
| 65 |
+
- β‘ **4x faster inference** than base model, runs locally on Apple Silicon
|
| 66 |
+
|
| 67 |
+
### Architecture Evolution
|
| 68 |
+
| Version | Strategy | Total | NEXT | RETRY | FORK | JOIN | META |
|
| 69 |
+
|---------|----------|-------|------|-------|------|------|------|
|
| 70 |
+
| v1 (base) | 800-iter policy training | 36.8% | 73% | 25% | 7% | 0% | 62% |
|
| 71 |
+
| v2 | + contrastive alignment | 55.3% | 36% | 58% | 93% | 67% | 25% |
|
| 72 |
+
| **v3** | **+ fork suppression** | **59.2%** | **68%** | **100%** | **86%** | **40%** | **0%** |
|
| 73 |
+
|
| 74 |
+
v3 fixes v2's FORK over-triggering problem. v2 had learned "forkable β FORK" blindly.
|
| 75 |
+
v3 correctly learns "forkable AND conditions favorable β FORK, otherwise NEXT".
|
| 76 |
+
|
| 77 |
+
## Training Details
|
| 78 |
+
|
| 79 |
+
### Three-Stage Training
|
| 80 |
+
|
| 81 |
+
**Stage A: Base Policy (iter 800)**
|
| 82 |
+
- Dataset: 554K instruction pairs from 89 workflow graphs
|
| 83 |
+
- 8 structural families (linear, retry, fork-join, escalation, etc.)
|
| 84 |
+
- Balanced decision distribution: NEXT 36%, JOIN 27%, META 13%, FORK 12%, RETRY 12%
|
| 85 |
+
|
| 86 |
+
**Stage B: Contrastive Alignment (iter 100)**
|
| 87 |
+
- Dataset: 20K curated samples with clean decision boundaries
|
| 88 |
+
- Contrastive pairs: FORK positives + hard negatives, JOIN positives + hard negatives
|
| 89 |
+
- Proportional representation across all decision types
|
| 90 |
+
|
| 91 |
+
**Stage C: Fork Suppression (iter 200)**
|
| 92 |
+
- Dataset: 4,600 targeted samples
|
| 93 |
+
- Focus: "forkable but blocked β NEXT" hard negatives
|
| 94 |
+
- Teaches: resource pressure, parallel depth, uncertainty block FORK
|
| 95 |
+
- Stabilizers: RETRY and NEXT anchors to prevent forgetting
|
| 96 |
+
|
| 97 |
+
### LoRA Configuration
|
| 98 |
+
| Parameter | Value |
|
| 99 |
+
|-----------|-------|
|
| 100 |
+
| Rank | 16 |
|
| 101 |
+
| Alpha (scale) | 32 (2.0x) |
|
| 102 |
+
| Dropout | 0.02 |
|
| 103 |
+
| Target layers | Last 28 of 32 |
|
| 104 |
+
| Target modules | q_proj, k_proj, v_proj, o_proj |
|
| 105 |
+
|
| 106 |
+
### Training Configuration
|
| 107 |
+
| Parameter | Value |
|
| 108 |
+
|-----------|-------|
|
| 109 |
+
| Framework | MLX (Apple Silicon native) |
|
| 110 |
+
| Hardware | Apple M4 Pro, 48GB unified memory |
|
| 111 |
+
| Stage A iters | 800 |
|
| 112 |
+
| Stage B iters | 100 |
|
| 113 |
+
| Stage C iters | 200 |
|
| 114 |
+
| Batch size | 4 |
|
| 115 |
+
| Learning rate | 2e-5 (fork-suppression stage) |
|
| 116 |
+
| Sequence length | 512 |
|
| 117 |
+
| Prompt masking | Yes (loss only on assistant tokens) |
|
| 118 |
+
|
| 119 |
+
## Usage
|
| 120 |
+
|
| 121 |
+
### With MLX (Apple Silicon)
|
| 122 |
+
|
| 123 |
+
```python
|
| 124 |
+
from mlx_lm import load, generate
|
| 125 |
+
from mlx_lm.sample_utils import make_sampler
|
| 126 |
+
|
| 127 |
+
model, tokenizer = load(
|
| 128 |
+
"Qwen/Qwen2.5-7B-Instruct",
|
| 129 |
+
adapter_path="ssaraf1/slm-workflow-planner-7b-v3"
|
| 130 |
+
)
|
| 131 |
+
|
| 132 |
+
messages = [
|
| 133 |
+
{"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"},
|
| 134 |
+
{"role": "user", "content": "Current node: VERIFY_POLICY (SYSTEM)\nOutcome: success\n\nState:\n goal_progress=0.35\n parallel_active=0\n resource_pressure=0.1\n retry_count=0\n\nEligible nodes:\n 1. FRAUD_SCREENING (SYSTEM) β produces: fraud_score\n 2. DAMAGE_ASSESSMENT (AGENT) β produces: damage_report\n\nForkable sets: [{FRAUD_SCREENING, DAMAGE_ASSESSMENT}]\nJoin-ready: []\n\nWhat decision type?"}
|
| 135 |
+
]
|
| 136 |
+
|
| 137 |
+
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
| 138 |
+
sampler = make_sampler(temp=0.0)
|
| 139 |
+
response = generate(model, tokenizer, prompt=prompt, max_tokens=10, sampler=sampler)
|
| 140 |
+
print(response) # Expected: FORK (low pressure, independent actors)
|
| 141 |
+
```
|
| 142 |
+
|
| 143 |
+
## What Makes v3 Special
|
| 144 |
+
|
| 145 |
+
### Fork Suppression β Correct Policy Boundaries
|
| 146 |
+
v2 over-triggered FORK whenever `forkable_sets` was present.
|
| 147 |
+
v3 learned the correct policy:
|
| 148 |
+
|
| 149 |
+
| Scenario | Topology | State | v2 Decision | v3 Decision |
|
| 150 |
+
|----------|----------|-------|-------------|-------------|
|
| 151 |
+
| Low pressure + independent | Forkable | Go parallel | FORK β
| FORK β
|
|
| 152 |
+
| High resource pressure | Forkable | Don't parallelize | FORK β | NEXT β
|
|
| 153 |
+
| Already in parallel | Forkable | Too deep | FORK β | NEXT β
|
|
| 154 |
+
| High uncertainty | Forkable | Risky | FORK β | NEXT β
|
|
| 155 |
+
| First retry failure | Not forkable | Retry available | NEXT β | RETRY β
|
|
| 156 |
+
|
| 157 |
+
### Remaining Challenges (v4 targets)
|
| 158 |
+
- **JOIN: 40%** β model struggles with join synchronization
|
| 159 |
+
- **META: 0%** β anomaly detection not yet learned
|
| 160 |
+
- These require a unified alignment approach (not sequential patching)
|
| 161 |
+
|
| 162 |
+
## Files
|
| 163 |
+
|
| 164 |
+
- `adapters.safetensors` β LoRA adapter weights (Stage A + B + C)
|
| 165 |
+
- `adapter_config.json` β LoRA configuration for MLX
|
| 166 |
+
|
| 167 |
+
## Citation
|
| 168 |
+
|
| 169 |
+
Part of the **Agentic Factory** project β building autonomous workflow orchestration
|
| 170 |
+
with SLM-powered planning on Apple Silicon.
|