PS:代碼補全、文檔生成相關的微調見:https://github.com/unit-mesh/unit-eval
聲明:本項目提供的數據集、LoRA 二進制,皆為OpenAI 生成或網上公開項目。我們僅提供了模型訓練相關教程,使用者實際訓練的內容所造成的一切後果由使用者本人負責。
對於工程師而言,我們可以顯而易見的看到ChatGPT 等大語言模型帶來的影響,藉此我們展開了AI 對於研發效能提升的研究—— 訓練了幾個LLaMA LoRA、ChatGLM LoRA 用來研究研發效能提升的方法。
這個項目是我們的研究成果,包括了一些視頻介紹、訓練好的模型、訓練代碼、訓練數據、訓練過程中的一些記錄。
訓練完的LoRA 見Release。
訓練Notebook:
LLaMA 系列在線視頻:
ChatGLM 系列在線視頻:
目錄:
相關數據轉換參見:https://github.com/unit-mesh/minions-data-prepare
PS:如果你需要的是更好的代碼生成,建議採用:https://huggingface.co/Salesforce/codegen-16B-mono
我們使用的是OpenBayes 提供的雲GPU:https://openbayes.com/console/signup?r=phodal_uVxU
OpenBayes 模型可以使用:
Roadmap:
Thanks: AIOS Club for OpenAI Key, Thanks OpenBayes for Cloud GPU
AI 感性提效依賴於對研發效能的標準化,並儘可能細地拆分每一個步驟。
為了訓練的結果更加準確,我們詳細拆分了軟件開發的步驟,以確保每一步生成的是準確,進而驅動出準確的結果。如下是我們早期拆分的一小部分細流程的示例:
我們需要拆分到每一個盡可能小的步驟,在每一個細化的步驟裡,餵入數據,才會讓AI 產生最大的複讀機效果。
Todos
我們使用非常簡單的instruct,並儘可能提供,以便於集成到工具中使用。如下:
對應的功能介紹:
從測試結果來看,隨著數據量的增多,比如20000 個代碼用例比10000 個代碼用例更加的“聰明”。
基本思路:
如下所示:

Design a User Story Mapping for ${domain} application based on your understanding. Here are the requirements:
1 . Your user story map should include only user tasks to demonstrate how users will interact with the application.
2 . Our user story map should be based on your understanding of the ${domain} application and its users, and should be
designed to address their needs and pain points.
3 . You may use any tools or formats you choose to create your user story map, but it should be easily shareable and
understandable by stakeholders.
4 . Your expression should be more concise and clear.
5 . Your return should be like as follows:
###
User Tasks:
1 . ...
###示例輸出:
User Tasks:
1. Browse and search for animations and comics
2. View details of animations and comics
3. Create an account
4. Log in to the account
5. Add animations and comics to favorites
6. Download animations and comics
7. Share animations and comics with friends
8. Rate and review animations and comics
9. Create and upload animations and comics
10. Participate in online forums and discussions
为下面的需求编写用户故事:${domain} 应用的 ${story_name} 功能。 要求如下:
1 . 必须要考虑尽可能考虑各种异常场景,添加更多的 AC。
2 . 你的返回模板如下所示:
###
用户故事:可以选择宝贝出行服务
作为 莉莉妈
我想 在滴滴打车的手机客户端里选择宝贝出行服务
以便于 我能够带宝宝打车出行的时候打到有儿童座椅的车
AC 1: 莉莉妈可以选择宝贝出行服务
假设 xxx
当 xxx
于是 xxx
###示例輸出:
用户故事:可以创建和上传动画和漫画
作为一个 Animation and Comics 应用的用户
我想要创建和上传动画和漫画
以便于我可以分享我的作品给其他用户
AC 1: 用户可以创建和上传动画和漫画
假设 用户已经登录到 Animation and Comics 应用
当 用户点击创建和上传动画和漫画按钮
于是 用户可以创建和上传动画和漫画
基本思路:

src/main下的Java 文件。 PostService(PostRepository, UserRepository, ImageService)
- fields: postRepository:PostRepository, userRepository:UserRepository, userPosts:Set<Post>, imageService:ImageService
- methods: findAll(): List<Post>, addNewPost(Post): Post, saveImageToPost(String, MultipartFile, Post): int
預期JSON 格式:
示例:
{"instruction":"Implement the method action","input":"com.thoughtworks.go.config.rules.AbstractDirective(DirectiveType, DirectiveType, String, String, String)n- fields: action:String, type:String, resource:String, configErrors:ConfigErrors, directiveType:DirectiveTypen- methods: validate(ValidationContext): void, isInvalid(String, List<String>): boolean, matchesAction(String): boolean, matchesType(Class<? extends Validatable>): boolean, matchesResource(String): boolean, errors(): ConfigErrors, addError(String, String): void, equals(Object): boolean, action(): String, type(): String, resource(): String, hashCode(): int, hasErrors(): boolean, getDirectiveType(): DirectiveType","output":"public abstract class AbstractDirective implements Directive {nn @ConfigAttribute(value = "action", optional = false)n protected String action;nn @ConfigAttribute(value = "type", optional = false)n protected String type;nn @ConfigValuen private String resource;nn private final ConfigErrors configErrors = new ConfigErrors();nn private DirectiveType directiveType;nn public AbstractDirective(DirectiveType allow) {n this.directiveType = allow;n }nn public AbstractDirective(DirectiveType allow, String action, String type, String resource) {n this.directiveType = allow;n this.action = action;n this.type = type;n this.resource = resource;n }nn @Overriden public String action() {n return this.action;n }n}n"}
格式規範:
包名.类名(类的构造类型)
- fields:成员变量集合(变量名:类型)
- methods:方法抽象集合(方法名(参数类型): 输出类型)
結果:
com.thoughtworks.go.config.rules.AbstractDirective(DirectiveType, DirectiveType, String, String, String)
- fields: action:String, type:String, resource:String, configErrors:ConfigErrors, directiveType:DirectiveType
- methods: validate(ValidationContext): void, isInvalid(String, List<String>): boolean, matchesAction(String): boolean, matchesType(Class<? extends Validatable>): boolean, matchesResource(String): boolean, errors(): ConfigErrors, addError(String, String): void, equals(Object): boolean, action(): String, type(): String, resource(): String, hashCode(): int, hasErrors(): boolean, getDirectiveType(): DirectiveType
val javaProcessor = JavaProcessor (file.readText())
val shotClass = javaProcessor.toShortClass() ? : return @forEach
javaProcessor
.removePackage()
.removeAllImport()
.removeLicenseInfoBeforeImport()
javaProcessor.splitMethods().forEach { (key, value) ->
CodegenPrompt (
instruction = " Implement the method $key " ,
input = shotClass.toString(),
output = value
). let { prompt ->
val output = Json .encodeToString(prompt)
File ( " $targetPath${key} .json " ).writeText(output)
}
}基本思路

語法分析思路:
src/main下的Java 文件map,如果同時存在對應的測試文件,則拉入的數據集中。 org.unitmesh.processor.TestClass(String, Int)
- fields: field1:String, field2:Int
- methods: method1(String, Int): String, method2(): Int
class TestProcessorTest {
@ Test
void test1 () {
}
@ Test
void test2 () {
}
}最後,生成的數據如下:
{"classInfo": "com.thoughtworks.go.security.AESEncrypter(AESCipherProvider)n- fields: ENCODER:Base64.Encoder, DECODER: Base64.Decoder, cipherProvider:AESCipherProvider, ivProvider:IVProvidern- methods: createIVProviderInstance(): IVProvider, canDecrypt(String): boolean, encrypt(String): String, decrypt(String): String, createSecretKeySpec(): SecretKeySpec", "testMethod": "public class AESEncrypterTest {nn private AESEncrypter aesEncrypter;nn @Testn public void shouldGenerateEncryptedText() throws CryptoException {n String encrypt = aesEncrypter.encrypt("p@ssw0rd");n assertThat(encrypt).startsWith("AES");n assertThat(encrypt.split(":")).hasSize(3);n }n}n", "id": "task_0"}
詳細代碼見:test-to-code.py
最後生成的prompt 示例如下:
You are a programmer and implementation a method with TDD. Here are the requirements:
1 . According follows class information and tests code to write a method.
2 . Try you best to thinking corner case.
3 . You only return the code, no explain.
class information:
###
io.github.robwin.swagger.test.AbstractContractValidator()
- methods: findExpectedPaths(Swagger, SwaggerAssertionConfig): Map<String,Path>, getPathsIncludingBasePath(Swagger):
Map<String,Path>, getPathsWithPrefix(Swagger, String): Map<String,Path>, isBlankOrSlash(String): boolean
###
test code:
###
/ **
* Tests AbstractContractValidator.
* /
@ RunWith (Enclosed.class)
public class AbstractContractValidatorTest {
/ **
* Tests getPathsIncludingBasePath().
* /
public static class GetPathsIncludingBasePath {
@ Test
public void shouldReturnPathsPrefixedIfBasePathSet() {
// given
Swagger swagger = buildSwaggerFrom("/swagger.json");
// when
Map<String, Path> paths = new DummyValidator().getPathsIncludingBasePath(swagger);
// then
paths.entrySet().forEach(e -> assertThat(e.getKey(), startsWith(swagger.getBasePath())));
}
}
/ **
* Tests findExpectedPaths().
* /
public static class FindExpectedPaths {
}
private static class DummyValidator extends AbstractContractValidator {
}
}
###
使用的是已有的Datasets,包括:
不過,這兩個代碼集質量都不高,但是基本可用。
格式如下:
instruction:
我想查找特定月份(monthly_id)下在某个日期(date)之前的所有费用(expense),以方便了解特定月份内的开销情况。
input:
data class ExpenseEntity(....)
output:
@Query("SELECT * FROM expense WHERE monthly_id = :recurringExpenseId AND date < :beforeDate")
suspend fun getAllExpensesForRecurringExpenseBeforeDate(recurringExpenseId: Long, beforeDate: LocalDate): List<ExpenseEntity>
evaluate("text to kotlin repository with class", "我想查询指定年龄的用户(User)的博客数量。n ###data class User(var age: Int,
val blogId: Int) data class Post(val title: String)###", 0.1, 0.75, 40, 4, 512)
@Query("SELECT COUNT(*) FROM User WHERE age = :age")
abstract fun getBlogCount(age: Int): Long
基本思路:
instruction和output兩部分, input為null。示例:
instruction: 介绍一下财通财通宝的基金管理人、基金托管人在履行各自职责的过程中,违反《基金法》?
(一)基金管理人、基金托管人在履行各自职责的过程中,违反《基金法》等法律法规的规定或者基金合同约定, 给基金财产或者基金份额持有人造成损害的,
应当分别对各自的行为依法承担赔偿责任;因共同行为给基金财产或者基金份额持有人造成损害的,应当承担连带赔偿责任,对 损失的赔偿,仅限于直接损失。
但是发生下列情况,当事人可以免责: 1.基金管理人及基金托管人按照中国证监会的规定或当时有效的法律法规的作为或不作为而造成的损失等;
2.基金管理人由于按照基金合同规定的投资原则而行使或不行使其投资权而造成的损失等; 3.不可抗力。
訓練:
訓練時間:
相關背景:
由於,我們的目標不是對模型調優、生成通用的模型,而是訓練特定用途的Lora。因此,我們沒有加入:Stanford Alpaca 中的數據, 故所需要時間更短,如8000+ 測試代碼只需要1 小時,3400+ 的用戶故事只需要25 分鐘。
訓練結果(LoRA)見:https://github.com/unit-mesh/unit-minions/releases/tag/v0.0.1
print(evaluate("write test", """
public Set<String> listFilesUsingJavaIO(String dir) {
return Stream.of(new File(dir).listFiles())
.filter(file -> !file.isDirectory())
.map(File::getName)
.collect(Collectors.toSet());
}
""", 0.1, 0.75, 40, 4, 512))
## Output:
public class ListFilesUsingJavaIOTest {
@Test
public void shouldListFilesUsingJavaIO() {
Set<String> files = ListFilesUsingJavaIO.listFilesUsingJavaIO(new File("dir"));
assertThat(files, containsInAnyOrder("file1", "file2", "file3"));
}
}
訓練結果(LoRA)見:https://github.com/unit-mesh/unit-minions/releases/tag/v0.0.2
注意:
--val_set_size 500--val_set_size 500--val_set_size 500示例輸出:
print(evaluate("create Agile user story for following topic: ", "购买电影票", 0.1, 0.75, 40, 4, 512))
用户故事:可以购买电影票
作为一个电影票购买者
我想在购买电影票应用中购买电影票
以便于我可以购买电影票
AC 1: 电影票购买者可以在购买电影票应用中购买电影票
假设 电影票购买者已经登录购买电影票应用
当 电影票购买者点击“购买电影票”按钮
于是 电影票购买者可以在购买电影票应用中购买电影票
AC 2: 电影票购买者可以在购买电影票应用中查看购买记录
假设 电影票购买者已经登录购买电影票应用
当 电影票购买者点击“查看购买记录”按钮
于是 电影票购买者可以在购买电影票应用中查看购买记录
AC 3: 电影票购买者可以在购买电影票应用中查看购买记录
假设 电影票购买者已经登录购买电影票应用
当 电影票购买者点击“查看购买记录”按��
訓練結果(LoRA)見:https://github.com/unit-mesh/unit-minions/releases/tag/v0.0.3
示例輸出:
print(evaluate("Implement the method rmFiles", "FileUtils:", 0.1, 0.75, 40, 4, 512))
public class FileUtils {
private FileUtils() {
}
public static void rmFiles(String path) {
File dir = new File(path);
File[] files = dir.listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
file.delete();
} else if (file.isDirectory()) {
FileUtils.rmFiles(file.getAbsolutePath());
}
}
}
}
}
轉換腳本:code/text-to-sql.py
直接從:datasets/sql/sql-train.jsonl
示例輸出:
evaluate("text to sql", "谁是最美丽的人", 0.1, 0.75, 40, 4, 512)
evaluate("text to sql", "小明今年几岁", 0.1, 0.75, 40, 4, 512)
evaluate("text to sql", "What hand guard system is used with a gas piston commando?", 0.1, 0.75, 40, 4, 512)
訓練:
示例1:
evaluate("Instruction: 创建用户故事nInput: 电影网站: 查看订单详情 nAnswer:")
Instruction: 创建用户故事
Input: 电影网站: 查看订单详情
Answer:
用户故事:可以查看订单详情
作为一个电影网站的用户
我想查看订单详情
以便于我可以了解订单的详细信息,如订单号、订单状态、订单内容等。
AC 1: 用户可以查看订单详情
假设 用户已经登录
当 用户点击查看订单详情按钮
于是 用户可以查看订单详情,包括订单号、订单状态、订单内容等。
AC 2: 用户可以查看订单详情
假设 用户没有登录
当 用户点击查看订单详情按钮
于是 用户被要求先登录,然后才能查看订单详情,包括订单号、订单状态、订单内容等。
示例2:
evaluate("Instruction: 创建用户故事nInput: 团购网站:用户注册nAnswer:")
Instruction: 创建用户故事
Input: 团购网站:用户注册
Answer:
团购网站的用户注册故事:
作为一个团购网站的用户
我想注册一个团购网站的用户账号
以便于我可以使用团购服务,如购买商品、服务等。
AC 1: 团购网站的用户注册账号
假设 用户输入了注册信息
当 用户提交注册信息
于是 用户可以成功注册一个团购网站的用户账号
AC 2: 团购网站的用户注册账号
假设 用户输入了错误的注册信息
当 用户提交注册信息
于是 用户可以被提示输入正确的注册信息,并重新提交注册信息