license: mit
language:
- en
- ko
- code
library_name: transformers
tags:
- code-llama
- code-review
- fine-tuning
- SFT
- LoRA
pipeline_tag: text-generation
base_model:
- codellama/CodeLlama-7b-hf
Model Card for codellama-7b-code-review
Model Details / λͺ¨λΈ μμΈ μ 보
πΊπΈ English
This model is fine-tuned from Meta's codellama/CodeLlama-7b-hf to review and provide feedback on code changes (diffs) from GitHub Pull Requests. It has been primarily trained on JavaScript and React code reviews, aiming to generate constructive feedback from a senior engineer's perspective on topics like code quality, architecture, performance, and conventions.
- Developed by: ken12377
- Model type: Causal Language Model
- Language(s): English, Korean, Diff format
- License: apache-2.0
- Finetuned from model:
codellama/CodeLlama-7b-hf
π°π· νκ΅μ΄
μ΄ λͺ¨λΈμ Metaμ codellama/CodeLlama-7b-hf λͺ¨λΈμ κΈ°λ°μΌλ‘, GitHub Pull Requestμ μ½λ λ³κ²½μ¬ν(diff)μ 리뷰νκ³ νΌλλ°±μ μ 곡νλλ‘ νμΈνλλμμ΅λλ€. μ£Όλ‘ JavaScriptμ React μ½λ 리뷰μ μ€μ μ λκ³ νμ΅λμμΌλ©°, μλμ΄ μμ§λμ΄μ κ΄μ μμ μ½λ νμ§, μν€ν
μ², μ±λ₯, 컨벀μ
λ±μ λν 건μ€μ μΈ νΌλλ°±μ μμ±νλ κ²μ λͺ©νλ‘ ν©λλ€.
- κ°λ°μ: ken12377
- λͺ¨λΈ μ’ λ₯: μΈκ³Ό κ΄κ³ μΈμ΄ λͺ¨λΈ (Causal Language Model)
- μΈμ΄: μμ΄, νκ΅μ΄, Diff νμ
- λΌμ΄μ μ€: apache-2.0
- νμΈνλ κΈ°λ° λͺ¨λΈ:
codellama/CodeLlama-7b-hf
Model Sources / λͺ¨λΈ μμ€
Uses / μ¬μ© μ 보
πΊπΈ English
Direct Use
This model can be used directly for code review automation. By providing code changes in diff format as input, the model will generate review comments.
Warning: The content generated by the model always requires review. The final decision must be made by a human developer.
Downstream Use
This model can be reused as a base for further fine-tuning on specific project's internal coding conventions or more specialized review criteria.
Out-of-Scope Use
This model is specialized for code review tasks. It may not perform well for other purposes such as general-purpose chatbots, code generation, or translation. Especially, inputting code that is not in diff format may lead to unexpected results.
π°π· νκ΅μ΄
μ§μ μ¬μ©
μ΄ λͺ¨λΈμ μ½λ 리뷰 μλνμ μ§μ μ¬μ©λ μ μμ΅λλ€. diff νμμ μ½λ λ³κ²½μ¬νμ μ
λ ₯μΌλ‘ μ 곡νλ©΄, λͺ¨λΈμ ν΄λΉ μ½λμ λν 리뷰 μ½λ©νΈλ₯Ό μμ±ν©λλ€.
κ²½κ³ : λͺ¨λΈμ΄ μμ±νλ λ΄μ©μ νμ κ²ν κ° νμνλ©°, μ΅μ’ κ²°μ μ κ°λ°μκ° μ§μ λ΄λ €μΌ ν©λλ€.
λ€μ΄μ€νΈλ¦Ό μ¬μ©
μ΄ λͺ¨λΈμ νΉμ νλ‘μ νΈμ λ΄λΆ μ½λ© 컨벀μ μ΄λ λ μ λ¬Ένλ 리뷰 κΈ°μ€μ νμ΅μν€κΈ° μν κΈ°λ° λͺ¨λΈλ‘ μ¬μ¬μ©λ μ μμ΅λλ€.
μ¬μ© λ²μ μΈ
μ΄ λͺ¨λΈμ μ½λ 리뷰 νμ€ν¬μ νΉνλμ΄ μμΌλ―λ‘, μΌλ°μ μΈ μ±λ΄ λνλ μ½λ μμ±, λ²μ λ±μ λ€λ₯Έ λͺ©μ μΌλ‘λ μ’μ μ±λ₯μ 보μ΄μ§ μμ μ μμ΅λλ€. νΉν diff νμμ΄ μλ μ½λλ₯Ό μ
λ ₯νλ©΄ μμμΉ λͺ»ν κ²°κ³Όκ° λμ¬ μ μμ΅λλ€.
Bias, Risks, and Limitations / νΈν₯, μν λ° νκ³
πΊπΈ English
- Data Bias: The model was trained on public GitHub Pull Request data, so it may be biased towards specific coding styles or patterns present in that data.
- Inaccuracy (Hallucination): The model may occasionally generate feedback that is factually incorrect or out of context. The generated reviews always need verification.
- Limited Knowledge: The model's knowledge is limited to the data at the time of fine-tuning and may not reflect the latest library or framework updates.
π°π· νκ΅μ΄
- λ°μ΄ν° νΈν₯: λͺ¨λΈμ 곡κ°λ GitHub Pull Request λ°μ΄ν°λ₯Ό κΈ°λ°μΌλ‘ νμ΅λμμΌλ―λ‘, ν΄λΉ λ°μ΄ν°μ μ‘΄μ¬νλ νΉμ μ½λ© μ€νμΌμ΄λ ν¨ν΄μ νΈν₯λμ΄ μμ μ μμ΅λλ€.
- λΆμ νμ±(νκ°): λͺ¨λΈμ λλλ‘ μ¬μ€κ³Ό λ€λ₯΄κ±°λ λ¬Έλ§₯μ λ§μ§ μλ νΌλλ°±μ μμ±ν μ μμ΅λλ€. μμ±λ 리뷰λ νμ κ²μ¦μ΄ νμν©λλ€.
- μ νλ μ§μ: λͺ¨λΈμ μ§μμ νμΈνλ μμ μ λ°μ΄ν°λ‘ νμ λμ΄ μμΌλ©°, μ΅μ λΌμ΄λΈλ¬λ¦¬λ νλ μμν¬ λ³κ²½μ¬νμ λ°μνμ§ λͺ»ν μ μμ΅λλ€.
Recommendations / κΆμ₯ μ¬ν
πΊπΈ English
Users should treat the code reviews generated by the model as a 'draft' or 'assistive tool' to help the development process, not as a final judgment. It is recommended that a human expert reviews critical changes.π°π· νκ΅μ΄
μ¬μ©μλ λͺ¨λΈμ΄ μμ±ν μ½λ 리뷰λ₯Ό μ΅μ’ μ μΈ νλ¨μ΄ μλ, κ°λ° κ³Όμ μ λλ 'μ΄μ' λλ '보쑰 λꡬ'λ‘ νμ©ν΄μΌ ν©λλ€. μ€μν λ³κ²½μ¬νμ λν΄μλ λ°λμ μΈκ° μ λ¬Έκ°μ κ²ν λ₯Ό κ±°μΉλ κ²μ κΆμ₯ν©λλ€.How to Get Started with the Model / λͺ¨λΈ μμνκΈ°
πΊπΈ English
Note: This model may be available in two versions: Adapter and Merged. Use the appropriate code for your model type.
1. Using the Adapter Model (ken12377/codellama-7b-code-review-adapter)
To use the adapter model, you must first load the base model and then apply the adapter using the peft library.
2. Using the Merged Model (ken12377/codellama-7b-code-review)
If the model is fully merged with the base model, you can load it directly without peft.
π°π· νκ΅μ΄
μ°Έκ³ : μ΄ λͺ¨λΈμ μ΄λν°(Adapter) μ λ³ν©λ(Merged) λ κ°μ§ λ²μ μΌλ‘ μ 곡λ μ μμ΅λλ€. μμ μ λͺ¨λΈ νμ μ λ§λ μ½λλ₯Ό μ¬μ©νμΈμ.
1. μ΄λν° λͺ¨λΈ μ¬μ©λ² (ken12377/codellama-7b-code-review-adapter)
μ΄λν° λͺ¨λΈμ μ¬μ©νλ €λ©΄, κΈ°λ° λͺ¨λΈμ λ¨Όμ λ‘λν ν peft λΌμ΄λΈλ¬λ¦¬λ₯Ό μ¬μ©ν΄ μ΄λν°λ₯Ό μ μ©ν΄μΌ ν©λλ€.
2. λ³ν©λ λͺ¨λΈ μ¬μ©λ² (ken12377/codellama-7b-code-review)
λͺ¨λΈμ΄ κΈ°λ° λͺ¨λΈκ³Ό μμ ν λ³ν©λ κ²½μ°, peft μμ΄ μ§μ λͺ¨λΈμ λ‘λνμ¬ μ¬μ©ν μ μμ΅λλ€.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
# --- Configuration (Choose one) ---
# 1. For Adapter Model
use_adapter = True
base_model_name = "codellama/CodeLlama-7b-hf"
adapter_or_model_name = "ken12377/codellama-7b-code-review-adapter"
# 2. For Merged Model
# use_adapter = False
# adapter_or_model_name = "ken12377/codellama-7b-code-review"
# --- Load Model and Tokenizer ---
if use_adapter:
base_model = AutoModelForCausalLM.from_pretrained(
base_model_name,
torch_dtype=torch.float16,
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained(adapter_or_model_name)
model = PeftModel.from_pretrained(base_model, adapter_or_model_name)
else:
tokenizer = AutoTokenizer.from_pretrained(adapter_or_model_name)
model = AutoModelForCausalLM.from_pretrained(
adapter_or_model_name,
torch_dtype=torch.float16,
device_map="auto",
)
model.eval()
# --- Inference ---
diff_code = """
--- a/src/components/LoginForm.js
+++ b/src/components/LoginForm.js
-import React from 'react';
+import React, { useState } from 'react';
-const LoginForm = () => (
- <form>
- <label>Email: <input type="email" /></label>
- <br />
- <label>Password: <input type="password" /></label>
- <br />
- <button type="submit">Log In</button>
- </form>
-);
+const LoginForm = () => {
+ const [credentials, setCredentials] = useState({ email: '', password: '' });
+ /* ... (rest of the diff code) ... */
+};
export default LoginForm;
"""
# Prompt in Korean
# λ§ν¬λ€μ΄ νμμ νΌλμ νΌνκΈ° μν΄ μ½λ λΈλ‘ ꡬλΆμλ₯Ό λ³μλ‘ λ§λ€μ΄ μ¬μ©ν©λλ€.
diff_block_delimiter = "```"
prompt = f"""### μ§μ:
μ 곡λ μ½λλ pull requestμ diff λ΄μ©μ
λλ€. μ½λμ κ°μ ν μ μλ λΆλΆμ λν΄ μ΅μ 3κ°μ§ νλͺ©μΌλ‘ λλμ΄ μμΈνκ³ κ΅¬μ²΄μ μΈ νΌλλ°±μ μ 곡ν΄μ£ΌμΈμ.
### μ
λ ₯:
{diff_block_delimiter}diff
{diff_code}
{diff_block_delimiter}
### μλ΅:
1. """
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7, repetition_penalty=1.2)
response = tokenizer.decode(outputs[0]len(inputs.input_ids[0]):], skip_special_tokens=True)
print(response)
Training Details / νμ΅ μμΈ μ 보
πΊπΈ English
Training Data
This model was fine-tuned using the review_dataset.json file, which contains public Pull Request data collected from GitHub. The dataset is structured in a instruction, input(diff), output(review comment) format.
Training Procedure
The model was fine-tuned using the QLoRA technique. It utilized the SFTTrainer from the trl library, applying 4-bit quantization and LoRA (Low-Rank Adaptation) for efficient training.
Training Hyperparameters
- model:
codellama/CodeLlama-7b-hf - max_seq_length: 4096
- lora_alpha: 128
- lora_dropout: 0.1
- lora_r: 64
- learning_rate: 2e-4
- optimizer: paged_adamw_32bit
- gradient_accumulation_steps: 8
- per_device_train_batch_size: 2
- max_steps: 1900
π°π· νκ΅μ΄
νμ΅ λ°μ΄ν°
μ΄ λͺ¨λΈμ GitHubμμ μμ§λ κ³΅κ° Pull Request λ°μ΄ν°λ₯Ό ν¬ν¨νλ review_dataset.json νμΌμ μ¬μ©νμ¬ νμΈνλλμμ΅λλ€. λ°μ΄ν°μ
μ instruction, input(diff), output(리뷰 μ½λ©νΈ) νμμΌλ‘ ꡬμ±λμ΄ μμ΅λλ€.
νμ΅ μ μ°¨
λͺ¨λΈμ QLoRA κΈ°λ²μ μ¬μ©νμ¬ νμΈνλλμμ΅λλ€. trl λΌμ΄λΈλ¬λ¦¬μ SFTTrainerλ₯Ό μ¬μ©νμΌλ©°, 4-bit μμνμ LoRA(Low-Rank Adaptation)λ₯Ό μ μ©νμ¬ ν¨μ¨μ μΈ νμ΅μ μ§ννμ΅λλ€.
νμ΅ νμ΄νΌνλΌλ―Έν°
- λͺ¨λΈ:
codellama/CodeLlama-7b-hf - μ΅λ μνμ€ κΈΈμ΄: 4096
- LoRA Alpha: 128
- LoRA Dropout: 0.1
- LoRA Rank (r): 64
- νμ΅λ₯ : 2e-4
- μ΅ν°λ§μ΄μ : paged_adamw_32bit
- Gradient Accumulation Steps: 8
- μ₯μΉλ³ νμ΅ λ°°μΉ ν¬κΈ°: 2
- μ΅λ μ€ν μ: 1900
Compute Infrastructure / μ»΄ν¨ν μΈνλΌ
πΊπΈ English
- Hardware Type: RunPod Cloud GPU
- Cloud Provider: RunPod
π°π· νκ΅μ΄
- νλμ¨μ΄ μ’ λ₯: RunPod ν΄λΌμ°λ GPU
- ν΄λΌμ°λ μ 곡μ 체: RunPod