ST-Coder-14B-LoRA
ST-Coder-14B-LoRA is a specialized LoRA adapter fine-tuned on Qwen2.5-Coder-14B-Instruct. It is specifically designed for Industrial Automation and PLC Programming tasks, with a strong focus on the IEC 61131-3 Structured Text (ST) language.
Note: This model is trained to generate high-quality, syntactically correct ST code for platforms like Codesys, TwinCAT, and Siemens SCL.
π Key Features
- Domain Specificity: Deeply understands industrial control logic (PID, Motion Control, Safety Logic, Communication Protocols).
- Strict Syntax: Adheres to IEC 61131-3 standards (e.g., correct usage of
FUNCTION_BLOCK,VAR,END_VAR, and strong typing). - Long Context: Trained with a context length of 8192 tokens to handle complex, multi-block program structures.
- Robustness: Enhanced via synthetic data distillation to avoid common syntax errors found in general-purpose coding models.
π» Quick Start
Requirements
pip install transformers peft torch accelerate
Inference Code (Python)
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# 1. Load Base Model
base_model_path = "Qwen/Qwen2.5-Coder-14B-Instruct"
model = AutoModelForCausalLM.from_pretrained(
base_model_path,
torch_dtype="auto",
device_map="auto",
trust_remote_code=True
)
tokenizer = AutoTokenizer.from_pretrained(base_model_path, trust_remote_code=True)
# 2. Load LoRA Adapter
lora_path = "RnniaSnow/ST-Coder-14B-LoRA"
model = PeftModel.from_pretrained(model, lora_path)
# 3. Generate Code
prompt = "Write a Function Block (ST) for a PID controller with anti-windup mechanism."
messages = [
{"role": "system", "content": "You are an expert IEC 61131-3 PLC programmer."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=1024,
temperature=0.2, # Low temperature for code precision
top_p=0.9
)
output_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(output_text)
π§ Training Details
This model was trained using LLaMA-Factory with the following configuration:
- Base Model: Qwen/Qwen2.5-Coder-14B-Instruct
- Training Method: LoRA (Low-Rank Adaptation)
- Target Modules:
all(Applied to all linear layers for maximum expressivity) - LoRA Rank: 64
- LoRA Alpha: 128
- Cutoff Length: 8192 tokens
- Flash Attention: Enabled (FA2)
- Precision: BF16
π Dataset
The training dataset (RnniaSnow/st-code-dataset) consists of:
- Golden Samples: High-quality, verified ST code snippets from real-world engineering projects.
- Synthetic Distillation: Generated using DeepSeek-V3 with strict syntax constraints and self-correction pipelines to ensure logical correctness.
β οΈ Disclaimer
While this model is optimized for industrial programming, LLM-generated code must always be verified and tested on a simulation environment before deployment to physical hardware. The author assumes no liability for damages caused by the use of this code in production environments.
- Downloads last month
- 31
Model tree for RnniaSnow/ST-Coder-14B-LoRA
Base model
Qwen/Qwen2.5-14B