ken123777's picture
Update README.md
b1ff199 verified
metadata
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