RnniaSnow commited on
Commit
195db16
·
verified ·
1 Parent(s): 93799bb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +69 -0
README.md CHANGED
@@ -33,3 +33,72 @@ It is specifically designed for **Industrial Automation** and **PLC Programming*
33
  ### Requirements
34
  ```bash
35
  pip install transformers peft torch accelerate
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  ### Requirements
34
  ```bash
35
  pip install transformers peft torch accelerate
36
+ ```
37
+
38
+ ### Inference Code (Python)
39
+
40
+ ```python
41
+ import torch
42
+ from transformers import AutoModelForCausalLM, AutoTokenizer
43
+ from peft import PeftModel
44
+
45
+ # 1. Load Base Model
46
+ base_model_path = "Qwen/Qwen2.5-Coder-14B-Instruct"
47
+ model = AutoModelForCausalLM.from_pretrained(
48
+ base_model_path,
49
+ torch_dtype="auto",
50
+ device_map="auto",
51
+ trust_remote_code=True
52
+ )
53
+ tokenizer = AutoTokenizer.from_pretrained(base_model_path, trust_remote_code=True)
54
+
55
+ # 2. Load LoRA Adapter
56
+ lora_path = "RnniaSnow/ST-Coder-14B-LoRA"
57
+ model = PeftModel.from_pretrained(model, lora_path)
58
+
59
+ # 3. Generate Code
60
+ prompt = "Write a Function Block (ST) for a PID controller with anti-windup mechanism."
61
+ messages = [
62
+ {"role": "system", "content": "You are an expert IEC 61131-3 PLC programmer."},
63
+ {"role": "user", "content": prompt}
64
+ ]
65
+
66
+ text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
67
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
68
+
69
+ generated_ids = model.generate(
70
+ **model_inputs,
71
+ max_new_tokens=1024,
72
+ temperature=0.2, # Low temperature for code precision
73
+ top_p=0.9
74
+ )
75
+
76
+ output_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
77
+ print(output_text)
78
+
79
+ ```
80
+
81
+ ## 🔧 Training Details
82
+
83
+ This model was trained using [LLaMA-Factory](https://github.com/hiyouga/LLaMA-Factory) with the following configuration:
84
+
85
+ * **Base Model**: Qwen/Qwen2.5-Coder-14B-Instruct
86
+ * **Training Method**: LoRA (Low-Rank Adaptation)
87
+ * **Target Modules**: `all` (Applied to all linear layers for maximum expressivity)
88
+ * **LoRA Rank**: 64
89
+ * **LoRA Alpha**: 128
90
+ * **Cutoff Length**: 8192 tokens
91
+ * **Flash Attention**: Enabled (FA2)
92
+ * **Precision**: BF16
93
+
94
+ ## 📂 Dataset
95
+
96
+ The training dataset (`RnniaSnow/st-code-dataset`) consists of:
97
+
98
+ 1. **Golden Samples**: High-quality, verified ST code snippets from real-world engineering projects.
99
+ 2. **Synthetic Distillation**: Generated using DeepSeek-V3 with strict syntax constraints and self-correction pipelines to ensure logical correctness.
100
+
101
+ ## ⚠️ Disclaimer
102
+
103
+ 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.
104
+