Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,155 @@
|
|
| 1 |
-
--
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
---
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
#
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
#
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
#
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
#
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
#
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
###
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
[More Information Needed]
|
| 158 |
-
|
| 159 |
-
### Compute Infrastructure
|
| 160 |
-
|
| 161 |
-
[More Information Needed]
|
| 162 |
-
|
| 163 |
-
#### Hardware
|
| 164 |
-
|
| 165 |
-
[More Information Needed]
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
-
|
| 197 |
-
## Model Card Contact
|
| 198 |
-
|
| 199 |
-
[More Information Needed]
|
|
|
|
| 1 |
+
lora-llama2-finetuned
|
| 2 |
+
=======================================
|
| 3 |
+
|
| 4 |
+
This model is a fine-tuned instruction-following Large Language Model (LLM) specialized in generating, analyzing, and explaining Dockerfiles. It was adapted from the Llama 2 7B Chat base model using the QLoRA efficient fine-tuning method.
|
| 5 |
+
|
| 6 |
+
=======================================
|
| 7 |
+
1. Model Description
|
| 8 |
+
=======================================
|
| 9 |
+
|
| 10 |
+
Model ID:
|
| 11 |
+
[YOUR_USERNAME/YOUR_REPO_NAME]
|
| 12 |
+
|
| 13 |
+
Base Model:
|
| 14 |
+
* Architecture: Llama 2 7 Billion Parameters
|
| 15 |
+
* Base Model Name: NousResearch/Llama-2-7b-chat-hf
|
| 16 |
+
|
| 17 |
+
Intended Use:
|
| 18 |
+
The primary function of this model is to serve as an expert assistant for containerization tasks. It performs best when prompted with an instruction about a specific application stack or a Dockerfile snippet that needs analysis.
|
| 19 |
+
* Generation: Creating valid Dockerfiles from natural language descriptions (e.g., "Create a Dockerfile for a multi-stage Rust application").
|
| 20 |
+
* Explanation: Providing step-by-step breakdowns of existing Dockerfiles.
|
| 21 |
+
* Refactoring: Suggesting best practices or optimizations for Docker commands.
|
| 22 |
+
|
| 23 |
+
Limitations & Ethical Considerations:
|
| 24 |
+
Critical Note on Scale: This model was fine-tuned on a very limited dataset (20 training examples).
|
| 25 |
+
* Generalization: Performance may be poor on instructions that deviate significantly from the training examples, and the model may exhibit signs of overfitting.
|
| 26 |
+
* Security: Generated Dockerfiles may contain insecure commands, outdated dependencies, or other security vulnerabilities. Always review and validate generated code before use in a production environment.
|
| 27 |
+
* Bias: The model inherits potential biases from its base model, Llama 2.
|
| 28 |
+
|
| 29 |
+
=======================================
|
| 30 |
+
2. Training Details
|
| 31 |
+
=======================================
|
| 32 |
+
|
| 33 |
+
The model was fine-tuned using the QLoRA (Quantized Low-Rank Adaptation) technique, which loads the base model in 4-bit precision and only trains a small set of adapter weights.
|
| 34 |
+
|
| 35 |
+
Configuration:
|
| 36 |
+
* Fine-Tuning Method: QLoRA (Efficiently trains adapters on a quantized base model.)
|
| 37 |
+
* LoRA Rank (r): 16 (Defines the rank of the update matrices.)
|
| 38 |
+
* LoRA Alpha (lora_alpha): 32 (Scaling factor for the LoRA weights.)
|
| 39 |
+
* Target Modules: ["q_proj", "v_proj"] (Only query and value attention projection layers were targeted.)
|
| 40 |
+
* Max Sequence Length: 512 tokens (Determines the input/output capacity.)
|
| 41 |
+
* Training Epochs: 3 (Number of passes over the entire dataset.)
|
| 42 |
+
* Final Validation Loss: 1.706886 (Indicates the loss on the small test set.)
|
| 43 |
+
|
| 44 |
+
=======================================
|
| 45 |
+
3. Training Data
|
| 46 |
+
=======================================
|
| 47 |
+
|
| 48 |
+
The model was trained on a custom instruction-tuning dataset designed to teach the model to follow specific prompts related to Dockerfiles.
|
| 49 |
+
|
| 50 |
+
Dataset Structure:
|
| 51 |
+
* Local File: /content/dockerfile_finetune.jsonl
|
| 52 |
+
* Format: Instruction-Response pairs, formatted for chat fine-tuning.
|
| 53 |
+
* Training Size: 20 examples
|
| 54 |
+
* Test Size: 3 examples
|
| 55 |
+
|
| 56 |
+
Prompt Template (REQUIRED for optimal results):
|
| 57 |
+
The inference pipeline must use the following template:
|
| 58 |
+
|
| 59 |
+
### Instruction:
|
| 60 |
+
[The user's request or question]
|
| 61 |
+
|
| 62 |
+
### Input:
|
| 63 |
+
[The context, such as an existing Dockerfile or code snippet]
|
| 64 |
+
|
| 65 |
+
### Response:
|
| 66 |
+
[The model's generated Dockerfile, explanation, or analysis]
|
| 67 |
+
|
| 68 |
+
=======================================
|
| 69 |
+
4. How to Use (Inference)
|
| 70 |
+
=======================================
|
| 71 |
+
|
| 72 |
+
Since this is a QLoRA adapter, you must load the base model (NousResearch/Llama-2-7b-chat-hf) and then merge the adapter weights from this repository.
|
| 73 |
+
|
| 74 |
+
Prerequisites:
|
| 75 |
+
pip install torch transformers accelerate bitsandbytes peft
|
| 76 |
+
|
| 77 |
+
Inference Code (Python):
|
| 78 |
+
(This section contains detailed Python code using transformers and peft to load and run the model. This code is essential for usage and should be copied directly.)
|
| 79 |
+
|
| 80 |
+
import torch
|
| 81 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 82 |
+
from peft import PeftModel
|
| 83 |
+
|
| 84 |
+
# --- Configuration ---
|
| 85 |
+
BASE_MODEL = "NousResearch/Llama-2-7b-chat-hf"
|
| 86 |
+
ADAPTER_MODEL = "[YOUR_USERNAME/YOUR_REPO_NAME]" # REPLACE ME
|
| 87 |
+
|
| 88 |
+
# 1. Load the base model in 4-bit (QLoRA)
|
| 89 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
| 90 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 91 |
+
BASE_MODEL,
|
| 92 |
+
device_map="auto",
|
| 93 |
+
torch_dtype=torch.float16,
|
| 94 |
+
load_in_4bit=True, # Critical for QLoRA
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
# 2. Load the LoRA Adapter Weights
|
| 98 |
+
try:
|
| 99 |
+
model = PeftModel.from_pretrained(model, ADAPTER_MODEL)
|
| 100 |
+
print(f"Successfully loaded LoRA adapters from {ADAPTER_MODEL}")
|
| 101 |
+
except Exception as e:
|
| 102 |
+
print(f"Error loading adapter: {e}. Ensure the adapter ID is correct.")
|
| 103 |
+
# Exit or handle error if adapter fails to load
|
| 104 |
+
|
| 105 |
+
# 3. Inference Function using the correct prompt template
|
| 106 |
+
def generate_docker_response(instruction: str, input_text: str = None) -> str:
|
| 107 |
+
# Construct the instruction-tuning prompt template
|
| 108 |
+
prompt = f"### Instruction:\n{instruction}\n\n"
|
| 109 |
+
if input_text:
|
| 110 |
+
prompt += f"### Input:\n{input_text}\n\n"
|
| 111 |
+
prompt += "### Response:\n"
|
| 112 |
+
|
| 113 |
+
# Tokenize and generate
|
| 114 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True).to(model.device)
|
| 115 |
+
|
| 116 |
+
with torch.no_grad():
|
| 117 |
+
outputs = model.generate(
|
| 118 |
+
**inputs,
|
| 119 |
+
max_new_tokens=512,
|
| 120 |
+
do_sample=True,
|
| 121 |
+
top_p=0.9,
|
| 122 |
+
temperature=0.7,
|
| 123 |
+
eos_token_id=tokenizer.eos_token_id
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
# Decode and clean the output
|
| 127 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 128 |
+
# Extract only the content after the "### Response:" tag
|
| 129 |
+
response_start = response.find("### Response:\n")
|
| 130 |
+
if response_start != -1:
|
| 131 |
+
return response[response_start + len("### Response:\n"):].strip()
|
| 132 |
+
return response
|
| 133 |
+
|
| 134 |
+
# --- Example Usage ---
|
| 135 |
+
|
| 136 |
+
instruction = "Generate a Dockerfile for a simple Go web service that compiles a main.go file and runs it."
|
| 137 |
+
print("--- Generating Dockerfile ---")
|
| 138 |
+
print(generate_docker_response(instruction))
|
| 139 |
+
|
| 140 |
+
print("\n--- Explaining a Dockerfile ---")
|
| 141 |
+
dockerfile_input = """
|
| 142 |
+
FROM node:20-alpine AS build
|
| 143 |
+
WORKDIR /app
|
| 144 |
+
COPY package*.json .
|
| 145 |
+
RUN npm install
|
| 146 |
+
COPY . .
|
| 147 |
+
RUN npm run build
|
| 148 |
+
|
| 149 |
+
FROM node:20-alpine
|
| 150 |
+
WORKDIR /app
|
| 151 |
+
COPY --from=build /app/dist /app/dist
|
| 152 |
+
CMD ["npm", "start"]
|
| 153 |
+
"""
|
| 154 |
+
instruction = "Explain this multi-stage Dockerfile step-by-step."
|
| 155 |
+
print(generate_docker_response(instruction, dockerfile_input))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|