Text Generation
PEFT
Safetensors
grpo
lora
trl
unsloth
reinforcement-learning
process-control
methanol
conversational
Instructions to use glitchfilter/methanol-apc with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use glitchfilter/methanol-apc with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/Qwen2.5-3B-Instruct-bnb-4bit") model = PeftModel.from_pretrained(base_model, "glitchfilter/methanol-apc") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Desktop
Weights of Model Trained Via Unsloth
Browse filesFiles changed (10)
- .gitattributes+36-35
- README.md+148-3
- adapter_config.jsonAdded+50
- adapter_model.safetensorsAdded+3
- chat_template.jinjaAdded+54
- plots/baseline_vs_trained.pngAdded
- plots/loss_curve.pngAdded
- plots/reward_curve.pngAdded
- tokenizer.jsonAdded+3
- tokenizer_config.jsonAdded+201
1234567891011121314151617181920212223242526272829303132333435*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text123456789101112131415161718192021222324252627282930313233343536*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -texttokenizer.json filter=lfs diff=lfs merge=lfs -text
123---license: mit---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148---base_model: unsloth/Qwen2.5-3B-Instruct-bnb-4bitlibrary_name: peftpipeline_tag: text-generationmodel_name: methanol-apctags:- base_model:adapter:unsloth/Qwen2.5-3B-Instruct-bnb-4bit- grpo- lora- peft- trl- unsloth- reinforcement-learning- process-control- methanollicense: apache-2.0---# Model Card for methanol-apcLoRA adapter for [`unsloth/Qwen2.5-3B-Instruct-bnb-4bit`](https://huggingface.co/unsloth/Qwen2.5-3B-Instruct-bnb-4bit), fine-tuned with **GRPO** ([Group Relative Policy Optimization](https://huggingface.co/papers/2402.03300)) using [Unsloth](https://github.com/unslothai/unsloth) to act as an autonomous **Advanced Process Control (APC)** operator for a methanol synthesis reactor.The agent reads simulated sensor readings (temperature, pressure, H₂/CO ratio, catalyst health, …) and emits a JSON control action — feed rates, cooling water flow, and compressor power — that is scored by the [`methanol-apc` OpenEnv environment](https://huggingface.co/spaces/glitchfilter/methanol-apc-env).- **Model on Hugging Face:** [glitchfilter/methanol-apc](https://huggingface.co/glitchfilter/methanol-apc)- **Environment:** [glitchfilter/methanol-apc-env (HF Space)](https://huggingface.co/spaces/glitchfilter/methanol-apc-env) · [Bhavneet1492/openenv-methanol-apc (GitHub)](https://github.com/Bhavneet1492/openenv-methanol-apc)- **Base model:** [unsloth/Qwen2.5-3B-Instruct-bnb-4bit](https://huggingface.co/unsloth/Qwen2.5-3B-Instruct-bnb-4bit)## Quick start```pythonfrom unsloth import FastLanguageModelfrom peft import PeftModelmodel, tokenizer = FastLanguageModel.from_pretrained(model_name="unsloth/Qwen2.5-3B-Instruct-bnb-4bit",max_seq_length=2048,load_in_4bit=True,)model = PeftModel.from_pretrained(model, "glitchfilter/methanol-apc")FastLanguageModel.for_inference(model)system_prompt = ("You are an AI controller for a methanol synthesis reactor. ""Output a JSON control action with fields: "'{"feed_rate_h2": <0-10>, "feed_rate_co": <0-5>, ''"cooling_water_flow": <0-100>, "compressor_power": <0-100>}.')sensors = "T=248.3°C P=85.0bar H2=4.50mol/s CO=2.20mol/s ratio=2.05 cool=55L/min cat_health=98%"messages = [{"role": "system", "content": system_prompt},{"role": "user", "content": f"Current sensor readings:\n{sensors}\n\nProvide control action as JSON:"},]prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)import torchinputs = tokenizer(prompt, return_tensors="pt").to(model.device)with torch.no_grad():out = model.generate(**inputs, max_new_tokens=128, temperature=0.3, do_sample=True,pad_token_id=tokenizer.eos_token_id)print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))```## Training procedureTrained with **GRPO** accelerated by Unsloth's 4-bit quantized base model and LoRA adapters.**Pipeline:** `LLM generates JSON action` → `reward fn parses & scores` → `env.step()` → `multi-component reward` → `GRPO update`.### Key design choices- **Curriculum learning** over three task types:- `startup` (40%) — easy: ramp reactor to operating temperature- `optimization` (35%) — medium: maximize profit at steady state- `disturbance_rejection` (25%) — hard: handle cooling system failures- **Multi-component reward** combining:1. Physics reward from `env.step` (× 0.55)2. Format-compliance bonus for valid JSON actions (+0.10)3. Action-quality score grounded in stoichiometry / cooling adequacy ([−0.30, +0.20])4. 3-step lookahead penalty to surface delayed thermal-runaway consequences ([−0.20, 0])- **Deterministic replay**: each prompt stores `(task, seed, num_warmup)` so all GRPO group completions evaluate against an identical environment state.### Hyperparameters| | ||---|---|| 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 |### Framework versions- PEFT 0.18.1- Unsloth (`git+https://github.com/unslothai/unsloth.git`)- TRL ≥ 0.15- `openenv-core[core]` ≥ 0.2.2## EvaluationThe trained agent is compared against a random-action baseline on the `optimization` task (5 episodes × 15 steps). Plots are produced by the training notebook and saved to [plots/](plots/):| Plot | File ||---|---|| Training loss | [plots/loss_curve.png](plots/loss_curve.png) || Reward per step (trained) | [plots/reward_curve.png](plots/reward_curve.png) || Baseline vs trained | [plots/baseline_vs_trained.png](plots/baseline_vs_trained.png) |## Intended use & limitationsThis adapter is a **research artifact** demonstrating GRPO-based fine-tuning for closed-loop chemical-process control on a *simulated* environment. It is **not** suitable for, and must not be deployed against, any real industrial reactor or safety-critical system. The simulator is a simplified model of methanol synthesis (ICI low-pressure process, Cu/ZnO/Al₂O₃ catalyst) and does not capture the full dynamics, instrumentation, or failure modes of a physical plant.## CitationsGRPO:```bibtex@article{shao2024deepseekmath,title = {{DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models}},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},year = {2024},eprint = {arXiv:2402.03300}}```Unsloth:```bibtex@software{unsloth2024,title = {{Unsloth: 2x faster, 50\% less memory LLM finetuning}},author = {Daniel Han and Michael Han and {Unsloth team}},url = {https://github.com/unslothai/unsloth},year = {2024}}```
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950{ "alora_invocation_tokens": null, "alpha_pattern": {}, "arrow_config": null, "auto_mapping": { "base_model_class": "Qwen2ForCausalLM", "parent_library": "transformers.models.qwen2.modeling_qwen2", "unsloth_fixed": true }, "base_model_name_or_path": "unsloth/Qwen2.5-3B-Instruct-bnb-4bit", "bias": "none", "corda_config": null, "ensure_weight_tying": false, "eva_config": null, "exclude_modules": null, "fan_in_fan_out": false, "inference_mode": true, "init_lora_weights": true, "layer_replication": null, "layers_pattern": null, "layers_to_transform": null, "loftq_config": {}, "lora_alpha": 32, "lora_bias": false, "lora_dropout": 0, "megatron_config": null, "megatron_core": "megatron.core", "modules_to_save": null, "peft_type": "LORA", "peft_version": "0.18.1", "qalora_group_size": 16, "r": 16, "rank_pattern": {}, "revision": null, "target_modules": [ "k_proj", "down_proj", "gate_proj", "q_proj", "v_proj", "up_proj", "o_proj" ], "target_parameters": null, "task_type": "CAUSAL_LM", "trainable_token_indices": null, "use_dora": false, "use_qalora": false, "use_rslora": false}123version https://git-lfs.github.com/spec/v1oid sha256:863653dd062cfbd7fdaa325a7190fe857cb5cff7f814f75052564849e1f44a30size 119801528123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354{%- if tools %} {{- '<|im_start|>system\n' }} {%- if messages[0]['role'] == 'system' %} {{- messages[0]['content'] }} {%- else %} {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }} {%- endif %} {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }} {%- for tool in tools %} {{- "\n" }} {{- tool | tojson }} {%- endfor %} {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}{%- else %} {%- if messages[0]['role'] == 'system' %} {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }} {%- else %} {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }} {%- endif %}{%- endif %}{%- for message in messages %} {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %} {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }} {%- elif message.role == "assistant" %} {{- '<|im_start|>' + message.role }} {%- if message.content %} {{- '\n' + message.content }} {%- endif %} {%- for tool_call in message.tool_calls %} {%- if tool_call.function is defined %} {%- set tool_call = tool_call.function %} {%- endif %} {{- '\n<tool_call>\n{"name": "' }} {{- tool_call.name }} {{- '", "arguments": ' }} {{- tool_call.arguments | tojson }} {{- '}\n</tool_call>' }} {%- endfor %} {{- '<|im_end|>\n' }} {%- elif message.role == "tool" %} {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %} {{- '<|im_start|>user' }} {%- endif %} {{- '\n<tool_response>\n' }} {{- message.content }} {{- '\n</tool_response>' }} {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %} {{- '<|im_end|>\n' }} {%- endif %} {%- endif %}{%- endfor %}{%- if add_generation_prompt %} {{- '<|im_start|>assistant\n' }}{%- endif %}123version https://git-lfs.github.com/spec/v1oid sha256:bd5948af71b4f56cf697f7580814c7ce8b80595ef985544efcacf716126a2e31size 11422356123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201{ "add_prefix_space": false, "backend": "tokenizers", "bos_token": null, "clean_up_tokenization_spaces": false, "eos_token": "<|im_end|>", "errors": "replace", "is_local": false, "model_max_length": 32768, "pad_token": "<|PAD_TOKEN|>", "padding_side": "left", "split_special_tokens": false, "tokenizer_class": "Qwen2Tokenizer", "unk_token": null, "added_tokens_decoder": { "151643": { "content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151644": { "content": "<|im_start|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151645": { "content": "<|im_end|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151646": { "content": "<|object_ref_start|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151647": { "content": "<|object_ref_end|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151648": { "content": "<|box_start|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151649": { "content": "<|box_end|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151650": { "content": "<|quad_start|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151651": { "content": "<|quad_end|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151652": { "content": "<|vision_start|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151653": { "content": "<|vision_end|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151654": { "content": "<|vision_pad|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151655": { "content": "<|image_pad|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151656": { "content": "<|video_pad|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true }, "151657": { "content": "<tool_call>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "151658": { "content": "</tool_call>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "151659": { "content": "<|fim_prefix|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "151660": { "content": "<|fim_middle|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "151661": { "content": "<|fim_suffix|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "151662": { "content": "<|fim_pad|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "151663": { "content": "<|repo_name|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "151664": { "content": "<|file_sep|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": false }, "151665": { "content": "<|PAD_TOKEN|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": false, "special": true } }}.gitattributes+36-35
README.md+148-3
adapter_config.jsonAdded+50
adapter_model.safetensorsAdded+3
chat_template.jinjaAdded+54
plots/baseline_vs_trained.pngAdded

plots/loss_curve.pngAdded

plots/reward_curve.pngAdded

tokenizer.jsonAdded+3
tokenizer_config.jsonAdded+201