Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,119 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: transformers
|
| 4 |
+
base_model: Qwen/Qwen2.5-Coder-14B-Instruct
|
| 5 |
+
datasets:
|
| 6 |
+
- RnniaSnow/st-code-dataset
|
| 7 |
+
language:
|
| 8 |
+
- en
|
| 9 |
+
pipeline_tag: text-generation
|
| 10 |
+
tags:
|
| 11 |
+
- code
|
| 12 |
+
- plc
|
| 13 |
+
- iec-61131-3
|
| 14 |
+
- structured-text
|
| 15 |
+
- industrial-automation
|
| 16 |
+
- qwen
|
| 17 |
+
- llama-factory
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# ST-Coder-14B
|
| 21 |
+
|
| 22 |
+
<div align="center">
|
| 23 |
+
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers_logo_name.png" width="400"/>
|
| 24 |
+
</div>
|
| 25 |
+
|
| 26 |
+
## 🤖 Model Description
|
| 27 |
+
|
| 28 |
+
**ST-Coder-14B** is a specialized code generation model fine-tuned on **Qwen2.5-Coder-14B-Instruct**. It is specifically optimized for **Industrial Automation** tasks, with a primary focus on the **IEC 61131-3 Structured Text (ST)** programming language.
|
| 29 |
+
|
| 30 |
+
Unlike general-purpose coding models, ST-Coder-14B has been trained on high-quality, domain-specific data to understand:
|
| 31 |
+
* **PLC Logic**: PID control, Motion Control, Safety logic, State Machines.
|
| 32 |
+
* **IEC 61131-3 Syntax**: Correct usage of `FUNCTION_BLOCK`, `VAR_INPUT`, `VAR_OUTPUT`, and strict typing rules.
|
| 33 |
+
* **Industrial Protocols**: Modbus, TCP/IP socket handling in ST, and vendor-specific nuances (Codesys, TwinCAT, Siemens SCL).
|
| 34 |
+
|
| 35 |
+
## 💻 Quick Start
|
| 36 |
+
|
| 37 |
+
### 1. Installation
|
| 38 |
+
|
| 39 |
+
```bash
|
| 40 |
+
pip install transformers torch accelerate
|
| 41 |
+
```
|
| 42 |
+
### 2. Inference with Transformers
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
import torch
|
| 46 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 47 |
+
|
| 48 |
+
# Load the model
|
| 49 |
+
model_id = "RnniaSnow/ST-Coder-14B"
|
| 50 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 51 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 52 |
+
model_id,
|
| 53 |
+
torch_dtype="auto",
|
| 54 |
+
device_map="auto"
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# Prepare the prompt
|
| 58 |
+
system_prompt = "You are an expert industrial automation engineer specializing in IEC 61131-3 Structured Text."
|
| 59 |
+
user_prompt = "Write a Function Block for a 3-axis motion control system with error handling."
|
| 60 |
+
|
| 61 |
+
messages = [
|
| 62 |
+
{"role": "system", "content": system_prompt},
|
| 63 |
+
{"role": "user", "content": user_prompt}
|
| 64 |
+
]
|
| 65 |
+
|
| 66 |
+
text = tokenizer.apply_chat_template(
|
| 67 |
+
messages,
|
| 68 |
+
tokenize=False,
|
| 69 |
+
add_generation_prompt=True
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
# Generate
|
| 73 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 74 |
+
generated_ids = model.generate(
|
| 75 |
+
**model_inputs,
|
| 76 |
+
max_new_tokens=2048,
|
| 77 |
+
temperature=0.2, # Low temperature is recommended for code generation
|
| 78 |
+
top_p=0.9
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
# Decode output
|
| 82 |
+
output = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 83 |
+
print(output)
|
| 84 |
+
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
### 3. Usage with vLLM (Recommended for Production)
|
| 88 |
+
|
| 89 |
+
```bash
|
| 90 |
+
vllm serve RnniaSnow/ST-Coder-14B --tensor-parallel-size 1 --max-model-len 8192
|
| 91 |
+
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
## 🔧 Training Details
|
| 95 |
+
|
| 96 |
+
This model was trained using [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory) with the following configuration:
|
| 97 |
+
|
| 98 |
+
* **Base Model**: Qwen/Qwen2.5-Coder-14B-Instruct
|
| 99 |
+
* **Finetuning Method**: Full LoRA Merge (Target modules: `all`)
|
| 100 |
+
* **Precision**: BF16
|
| 101 |
+
* **Context Window**: 8192 tokens
|
| 102 |
+
* **Optimizer**: AdamW (Paged)
|
| 103 |
+
* **Learning Rate Strategy**: Cosine with warmup
|
| 104 |
+
|
| 105 |
+
The training data includes a mix of:
|
| 106 |
+
|
| 107 |
+
1. **Golden Samples**: Verified ST code from real-world engineering projects.
|
| 108 |
+
2. **Synthetic Data**: High-quality instruction-response pairs generated via DeepSeek-V3 distillation, focusing on edge cases and complex logic.
|
| 109 |
+
|
| 110 |
+
## ⚠️ Disclaimer & Safety
|
| 111 |
+
|
| 112 |
+
**Industrial Control Systems (ICS) carry significant physical risks.** * This model generates code based on statistical probabilities and does **not** guarantee functional correctness or safety.
|
| 113 |
+
|
| 114 |
+
* **Always** verify, simulate, and test generated code in a safe environment before deploying to physical hardware (PLCs, robots, drives).
|
| 115 |
+
* The authors assume no liability for any damage or injury resulting from the use of this model.
|
| 116 |
+
|
| 117 |
+
## 📜 License
|
| 118 |
+
|
| 119 |
+
This model is licensed under the [MIT License](https://opensource.org/licenses/MIT).
|