Views
No views yet
unsloth/Qwen2.5-3B-Instruct-bnb-4bit, fine-tuned with GRPO (Group Relative Policy Optimization) using Unsloth to act as an autonomous Advanced Process Control (APC) operator for a methanol synthesis reactor.methanol-apc OpenEnv environment.1from unsloth import FastLanguageModel
2from peft import PeftModel
3
4model, tokenizer = FastLanguageModel.from_pretrained(
5 model_name="unsloth/Qwen2.5-3B-Instruct-bnb-4bit",
6 max_seq_length=2048,
7 load_in_4bit=True,
8)
9model = PeftModel.from_pretrained(model, "glitchfilter/methanol-apc")
10FastLanguageModel.for_inference(model)
11
12system_prompt = (
13 "You are an AI controller for a methanol synthesis reactor. "
14 "Output a JSON control action with fields: "
15 '{"feed_rate_h2": <0-10>, "feed_rate_co": <0-5>, '
16 '"cooling_water_flow": <0-100>, "compressor_power": <0-100>}.'
17)
18sensors = "T=248.3°C P=85.0bar H2=4.50mol/s CO=2.20mol/s ratio=2.05 cool=55L/min cat_health=98%"
19
20messages = [
21 {"role": "system", "content": system_prompt},
22 {"role": "user", "content": f"Current sensor readings:\n{sensors}\n\nProvide control action as JSON:"},
23]
24prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
25
26import torch
27inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
28with torch.no_grad():
29 out = model.generate(**inputs, max_new_tokens=128, temperature=0.3, do_sample=True,
30 pad_token_id=tokenizer.eos_token_id)
31print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))LLM generates JSON action → reward fn parses & scores → env.step() → multi-component reward → GRPO update.startup (40%) — easy: ramp reactor to operating temperatureoptimization (35%) — medium: maximize profit at steady statedisturbance_rejection (25%) — hard: handle cooling system failuresenv.step (× 0.55)(task, seed, num_warmup) so all GRPO group completions evaluate against an identical environment state.| Base model | unsloth/Qwen2.5-3B-Instruct-bnb-4bit (4-bit) |
LoRA r / alpha / dropout | 16 / 32 / 0 |
| LoRA target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Max sequence length | 2048 |
| Max completion length | 120 tokens |
| Train steps | 200 |
| Per-device batch × grad accum | 2 × 4 |
GRPO group size (num_generations) | 8 |
| Learning rate | 5e-6 |
| Warmup ratio | 0.05 |
| Max grad norm | 1.0 |
| Sampling temperature | 0.7 |
| KL coefficient | 0.05 |
| Precision | fp16 (bf16 where supported) |
| Gradient checkpointing | Unsloth |
| Prompt dataset size | 300 |
git+https://github.com/unslothai/unsloth.git)openenv-core[core] ≥ 0.2.2optimization task (5 episodes × 15 steps). Plots are produced by the training notebook and saved to plots/:| Plot | File |
|---|---|
| Training loss | plots/loss_curve.png |
| Reward per step (trained) | plots/reward_curve.png |
| Baseline vs trained | plots/baseline_vs_trained.png |
1@article{shao2024deepseekmath,
2 title = {{DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models}},
3 author = {Zhihong Shao and Peiyi Wang and Qihao Zhu and Runxin Xu and Junxiao Song and Mingchuan Zhang and Y. K. Li and Y. Wu and Daya Guo},
4 year = {2024},
5 eprint = {arXiv:2402.03300}
6}1@software{unsloth2024,
2 title = {{Unsloth: 2x faster, 50\% less memory LLM finetuning}},
3 author = {Daniel Han and Michael Han and {Unsloth team}},
4 url = {https://github.com/unslothai/unsloth},
5 year = {2024}
6}