FaithOR-Detector-4B

A Qwen3-4B detector that reads a natural-language optimization problem, a numbered candidate mathematical model and the model's own solver result, and reports which components are semantically wrong, what kind of error each one is, and whether a required constraint is missing. A frozen writer then applies one targeted repair. The detector is a plain causal LM; the diagnosis is generated text, no classification head is added.

Input and output

The prompt contains the problem, the solver status and objective of the candidate model, and the model with every component numbered (S sets, P parameters, V variables, O1 objective, C constraints), followed by a fixed task instruction. The response is one short check line and a JSON diagnosis:

Checked 12 components against the problem.
{"errors": [{"id": "V1", "type": "var_to_int"}], "missing": false}

Error types: var_to_int, var_to_bin, var_to_cont, var_bound, con_sense, num_value, con_structure, con_extra, obj_sense, obj_expr. A clean model gets {"errors": [], "missing": false}. Use the prompt builder and parser from the code repository; an unparsable response is treated as an abstention, not as a clean verdict. Thinking mode must be disabled.

Usage

vllm serve QMJWang/FaithOR-Detector-4B --served-model-name faithor --port 8000 --max-model-len 16384
pip install -e .            # in the FaithOR code repository
or-detect --input examples/detector_input.jsonl --output outputs/detection.jsonl --model faithor
or-repair --input examples/problems.jsonl --out outputs/ours \
  --writer-model <writer> --writer-url http://localhost:8001/v1 \
  --coder-model <writer> --coder-url http://localhost:8001/v1 \
  --detector-model faithor --detector-url http://localhost:8000/v1

Decode greedily (temperature 0, max 512 new tokens).

Provenance and training

These weights are the detector evaluated in the paper. They were trained from Qwen/Qwen3-4B on the supervision now published as FaithOR-Supervision, through a sequence of exploratory SFT and GRPO runs; the merged tensor file has 398 tensors, 8,044,982,080 bytes, SHA256 a34bdfb63af9e4a67b7cbf0d43003ebf25bc893f510984bc0d65b618fb7753e0. In the one-round repair harness (Qwen3.6-35B-A3B as writer and coder, seven benchmarks, 1,511 problems, solver-certified optimality with relative tolerance 1e-4) this checkpoint scores 92.55 ± 0.10% over five runs. From those exploratory runs we distilled the fixed three-step pipeline below, released in the code repository; trained from scratch on the same data it scores 1,391 and 1,394 / 1,511 in two runs of the same harness, against 1,398 for these weights in a single run.

The recipe: two supervised stages, then a short GRPO stage. The two SFT stage files are published with the dataset (stages configuration) in the exact row order used here. Both SFT stages are LoRA fine-tuning on the attention and MLP projections (q,k,v,o,gate,up,down), alpha = 2 × rank, dropout 0.05, AdamW without weight decay, 5% warm-up then cosine decay, gradient accumulation 8, one epoch, seed 20261013. The loss is computed on response tokens only, with token weights 10 on the first decision token of the errors list, 3 on component IDs, error types and the missing value, and 1 elsewhere; each example is normalized by its weight sum.

Stage Data Rows LoRA rank Learning rate Max length Steps Wall time
1. General supervision data/sft_stage1.jsonl (the optmath and resocratic rows) 16,939 64 1e-4 8192 2,118 3.6 h
2. Semantic contracts data/sft_stage2.jsonl (the 13 simulated families, then the 1,509 replay rows) 9,189 16 6e-6 8192 1,149 1.0 h

Stage 2 starts from the merged stage-1 model and its adapter is merged into that model. Stage 1 teaches the protocol and general error recognition from real writer formulations; stage 2 calibrates semantic conventions (implicit integer domains, exact vs. at-least ratios, shared capacities, net-profit objectives, prerequisites) on the simulated contract families while replaying 1,509 real writer formulations so the model does not drift toward the simulator's templates.

Stage 3: GRPO (50 steps). Starting from the merged stage-2 model, full-parameter GRPO with verl 0.9.1 and vLLM 0.30 rollouts on the grpo train split (3,706 prompts over writer-generated formulations): batch 32 prompts, 8 samples per prompt at temperature 1.0, learning rate 1e-6, KL coefficient 0.001 against the stage-2 reference, no entropy bonus, prompt limit 2,400 tokens and response limit 512, FSDP with parameter and optimizer offload on two GPUs. The reward is rule-based (training/grpo_reward.py): −1 for an unparsable response, +1 / −1 for a correct model left alone / wrongly flagged, −0.5 for an erroneous model reported clean, otherwise component-localization F1 plus up to 0.2 for correct error types. Checkpoints were taken every 25 steps; the 50-step checkpoint gave the score above.

Stage Base Data Method Steps GPUs Wall time
3. GRPO merged stage-2 model grpo train, 3,706 prompts full-parameter GRPO, lr 1e-6, 32 × 8 rollouts 50 2 2.9 h

Reproduce with the code repository (first restore the upstream problem text in the dataset with scripts/rehydrate.py, see the dataset card):

python training/train.py --config configs/training.json --stage sft1 --base Qwen/Qwen3-4B \
  --data-root ../FaithOR-Supervision --out checkpoints/stage1
python training/sft.py --base Qwen/Qwen3-4B --data ../FaithOR-Supervision/data/sft_train.jsonl --out checkpoints/stage1 --merge-only
python training/train.py --config configs/training.json --stage sft2 --base checkpoints/stage1/merged \
  --data-root ../FaithOR-Supervision --out checkpoints/stage2
python training/sft.py --base checkpoints/stage1/merged --data ../FaithOR-Supervision/data/sft_train.jsonl --out checkpoints/stage2 --merge-only
python training/train.py --config configs/training.json --stage grpo --base checkpoints/stage2/merged \
  --data-root ../FaithOR-Supervision --out checkpoints/grpo      # verl environment; convert global_step_50 with verl.model_merger

Environment. NVIDIA RTX PRO 5000 Blackwell GPUs (48 GB), CUDA 13.2. SFT stages: one GPU each, PyTorch 2.14.1, Transformers 5.18.0, PEFT 0.21.2, bf16 frozen base, peak allocated memory 13.7 GB (stage 1) and 10.3 GB (stage 2); stage 1 processed 29.4 M tokens, stage 2 7.3 M tokens. GRPO: two GPUs, verl 0.9.1, vLLM 0.30.0, PyTorch 2.13.0, about 210 s per step.

Terms

Base model: Qwen/Qwen3-4B (Apache 2.0). Training-data terms are described in the dataset card.

Downloads last month
25
Safetensors
Model size
4B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for QMJWang/FaithOR-Detector-4B

Finetuned
Qwen/Qwen3-4B
Adapter
(1205)
this model
Adapters
1 model

Dataset used to train QMJWang/FaithOR-Detector-4B