LLM4PLC: Harnessing Large Language Models for Verifiable Programming of PLCs in Industrial Control Systems

📄 arXiv: 2401.05443v1 📥 PDF

作者: Mohamad Fakih, Rahul Dharmaji, Yasamin Moghaddas, Gustavo Quiros Araya, Oluwatosin Ogundare, Mohammad Abdullah Al Faruque

分类: cs.SE, cs.AI, cs.CL, cs.PL

发布日期: 2024-01-08

备注: 12 pages; 8 figures; Appearing in the 46th International Conference on Software Engineering: Software Engineering in Practice; for demo website, see https://sites.google.com/uci.edu/llm4plc/home

DOI: 10.1145/3639477.3639743


💡 一句话要点

提出LLM4PLC以解决工业控制系统中PLC编程的可验证性问题

🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)

关键词: 大型语言模型 可编程逻辑控制器 工业控制系统 代码生成 用户反馈 外部验证 模型微调 提示工程

📋 核心要点

  1. 现有的LLMs在工业控制系统编程中存在生成代码缺乏执行保证和可解释性不足的问题。
  2. 本文提出的LLM4PLC通过用户反馈和外部验证工具,优化了LLMs的代码生成过程。
  3. 实验结果显示,使用该方法后,生成成功率和代码质量均显著提升,验证了其有效性。

📝 摘要(中文)

尽管大型语言模型(LLMs)在自动代码生成中占据主导地位,但仍存在缺乏执行保证、可解释性不足以及对特定编程语言支持不佳等问题。现有的LLMs如GPT-4和LLaMa2无法为可编程逻辑控制器(PLCs)生成有效的工业控制系统程序。为此,本文提出了LLM4PLC,一个基于用户反馈和外部验证工具的迭代生成管道。通过使用提示工程和LoRAs进行模型微调,我们在FischerTechnik制造测试平台上验证了该系统,展示了LLMs如何从生成结构性错误的代码演变为生成可验证的正确程序。实验结果表明,生成成功率从47%提升至72%,代码质量评分从2.25/10提升至7.75/10。

🔬 方法详解

问题定义:本文旨在解决现有大型语言模型在工业控制系统中生成可编程逻辑控制器(PLC)代码时的有效性和可验证性问题。现有方法在生成代码时缺乏执行保证,导致生成的代码可能存在结构性错误。

核心思路:LLM4PLC的核心思路是通过用户引导的迭代生成过程,结合外部验证工具(如语法检查器、编译器和SMV验证器),来提升生成代码的质量和可验证性。这样的设计旨在通过反馈机制不断优化生成结果。

技术框架:该方法的整体架构包括用户反馈收集、代码生成、外部验证和结果优化四个主要模块。用户反馈用于指导生成过程,外部验证工具用于确保生成代码的正确性。

关键创新:LLM4PLC的主要创新在于结合用户反馈与外部验证工具,形成一个闭环的代码生成和验证流程。这与传统的单一生成模型方法有本质区别,后者往往缺乏有效的反馈和验证机制。

关键设计:在技术细节上,本文采用了提示工程和LoRAs进行模型微调,以增强生成能力。同时,设置了特定的损失函数来优化生成代码的结构和可执行性。

🖼️ 关键图片

fig_0
fig_1
fig_2

📊 实验亮点

实验结果显示,LLM4PLC显著提升了代码生成的成功率,从47%提高至72%;同时,专家评估的代码质量评分从2.25/10提升至7.75/10,表明该方法在生成可验证代码方面的有效性。

🎯 应用场景

该研究的潜在应用领域包括工业自动化、制造业和智能控制系统等。通过提高PLC编程的可验证性,LLM4PLC能够帮助工程师更高效地开发和维护复杂的控制系统,降低错误率,提高生产效率,具有重要的实际价值和未来影响。

📄 摘要(原文)

Although Large Language Models (LLMs) have established pre-dominance in automated code generation, they are not devoid of shortcomings. The pertinent issues primarily relate to the absence of execution guarantees for generated code, a lack of explainability, and suboptimal support for essential but niche programming languages. State-of-the-art LLMs such as GPT-4 and LLaMa2 fail to produce valid programs for Industrial Control Systems (ICS) operated by Programmable Logic Controllers (PLCs). We propose LLM4PLC, a user-guided iterative pipeline leveraging user feedback and external verification tools including grammar checkers, compilers and SMV verifiers to guide the LLM's generation. We further enhance the generation potential of LLM by employing Prompt Engineering and model fine-tuning through the creation and usage of LoRAs. We validate this system using a FischerTechnik Manufacturing TestBed (MFTB), illustrating how LLMs can evolve from generating structurally flawed code to producing verifiably correct programs for industrial applications. We run a complete test suite on GPT-3.5, GPT-4, Code Llama-7B, a fine-tuned Code Llama-7B model, Code Llama-34B, and a fine-tuned Code Llama-34B model. The proposed pipeline improved the generation success rate from 47% to 72%, and the Survey-of-Experts code quality from 2.25/10 to 7.75/10. To promote open research, we share the complete experimental setup, the LLM Fine-Tuning Weights, and the video demonstrations of the different programs on our dedicated webpage.