rafiaa commited on
Commit
c80b2e7
Β·
verified Β·
1 Parent(s): 2807915

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: peft
3
+ base_model: codellama/CodeLlama-7b-Instruct-hf
4
+ tags:
5
+ - terraform
6
+ - terraform-configuration
7
+ - infrastructure-as-code
8
+ - iac
9
+ - hashicorp
10
+ - codellama
11
+ - lora
12
+ - qlora
13
+ - peft
14
+ - code-generation
15
+ - devops
16
+ - cloud
17
+ - automation
18
+ - configuration-management
19
+ license: apache-2.0
20
+ language:
21
+ - en
22
+ pipeline_tag: text-generation
23
+ ---
24
+
25
+ # terraform-codellama-7b
26
+
27
+ A specialized LoRA fine-tuned model for Terraform infrastructure-as-code generation, built on CodeLlama-7b-Instruct-hf. This model excels at generating Terraform configurations, HCL (HashiCorp Configuration Language) code, and infrastructure automation scripts.
28
+
29
+ ## Model Description
30
+
31
+ This model is a LoRA (Low-Rank Adaptation) fine-tuned version of CodeLlama-7b-Instruct-hf, specifically optimized for generating Terraform configuration files. It was trained on public Terraform Registry documentation to understand Terraform syntax, resource configurations, and best practices.
32
+
33
+ ### Key Features
34
+
35
+ - **Specialized for Terraform**: Fine-tuned specifically for infrastructure-as-code generation
36
+ - **Efficient Training**: Uses QLoRA (4-bit quantization + LoRA) for memory-efficient training
37
+ - **Public Data Only**: Trained exclusively on public Terraform Registry documentation
38
+ - **Production Ready**: Optimized for real-world Terraform development workflows
39
+
40
+ ## Model Details
41
+
42
+ - **Developed by**: Rafi Al Attrach, Patrick Schmitt, Nan Wu, Helena Schneider, Stefania Saju (TUM + IBM Research Project)
43
+ - **Model type**: LoRA fine-tuned CodeLlama
44
+ - **Language(s)**: English
45
+ - **License**: Apache 2.0
46
+ - **Finetuned from**: [codellama/CodeLlama-7b-Instruct-hf](https://huggingface.co/codellama/CodeLlama-7b-Instruct-hf)
47
+ - **Training method**: QLoRA (4-bit quantization + LoRA)
48
+
49
+ ### Technical Specifications
50
+
51
+ - **Base Model**: CodeLlama-7b-Instruct-hf
52
+ - **LoRA Rank**: 64
53
+ - **LoRA Alpha**: 16
54
+ - **Target Modules**: q_proj, v_proj
55
+ - **Training Epochs**: 3
56
+ - **Max Sequence Length**: 512
57
+ - **Quantization**: 4-bit (fp4)
58
+
59
+ ## Uses
60
+
61
+ ### Direct Use
62
+
63
+ This model is designed for:
64
+ - Generating Terraform configuration files
65
+ - Infrastructure-as-code development
66
+ - Terraform resource configuration
67
+ - DevOps automation
68
+ - Cloud infrastructure planning
69
+
70
+ ### Example Use Cases
71
+
72
+ ```python
73
+ # Generate AWS EC2 instance configuration
74
+ prompt = "Create a Terraform configuration for an AWS EC2 instance with t3.medium instance type"
75
+ ```
76
+
77
+ ```python
78
+ # Generate Azure resource group
79
+ prompt = "Create a Terraform configuration for an Azure resource group in West Europe"
80
+ ```
81
+
82
+ ```python
83
+ # Generate GCP compute instance
84
+ prompt = "Create a Terraform configuration for a GCP compute instance with Ubuntu 20.04"
85
+ ```
86
+
87
+ ## How to Get Started
88
+
89
+ ### Installation
90
+
91
+ ```bash
92
+ pip install transformers torch peft accelerate bitsandbytes
93
+ ```
94
+
95
+ ### Loading the Model
96
+
97
+ #### GPU Usage (Recommended)
98
+ ```python
99
+ from transformers import AutoTokenizer, AutoModelForCausalLM
100
+ from peft import PeftModel
101
+ import torch
102
+
103
+ # Load base model with 4-bit quantization (GPU)
104
+ base_model = "codellama/CodeLlama-7b-Instruct-hf"
105
+ model = AutoModelForCausalLM.from_pretrained(
106
+ base_model,
107
+ load_in_4bit=True,
108
+ torch_dtype=torch.float16,
109
+ device_map="auto"
110
+ )
111
+
112
+ # Load LoRA adapter
113
+ model = PeftModel.from_pretrained(model, "rafiaa/terraform-codellama-7b")
114
+ tokenizer = AutoTokenizer.from_pretrained(base_model)
115
+
116
+ # Set pad token
117
+ if tokenizer.pad_token is None:
118
+ tokenizer.pad_token = tokenizer.eos_token
119
+ ```
120
+
121
+ #### CPU Usage (Alternative)
122
+ ```python
123
+ from transformers import AutoTokenizer, AutoModelForCausalLM
124
+ from peft import PeftModel
125
+ import torch
126
+
127
+ # Load base model (CPU compatible)
128
+ base_model = "codellama/CodeLlama-7b-Instruct-hf"
129
+ model = AutoModelForCausalLM.from_pretrained(
130
+ base_model,
131
+ torch_dtype=torch.float32,
132
+ device_map="cpu"
133
+ )
134
+
135
+ # Load LoRA adapter
136
+ model = PeftModel.from_pretrained(model, "rafiaa/terraform-codellama-7b")
137
+ tokenizer = AutoTokenizer.from_pretrained(base_model)
138
+
139
+ # Set pad token
140
+ if tokenizer.pad_token is None:
141
+ tokenizer.pad_token = tokenizer.eos_token
142
+ ```
143
+
144
+ ### Usage Example
145
+
146
+ ```python
147
+ def generate_terraform(prompt, max_length=512):
148
+ inputs = tokenizer(prompt, return_tensors="pt")
149
+
150
+ with torch.no_grad():
151
+ outputs = model.generate(
152
+ **inputs,
153
+ max_length=max_length,
154
+ temperature=0.7,
155
+ do_sample=True,
156
+ pad_token_id=tokenizer.eos_token_id
157
+ )
158
+
159
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
160
+
161
+ # Example usage
162
+ prompt = "Create a Terraform configuration for an AWS S3 bucket with versioning enabled"
163
+ result = generate_terraform(prompt)
164
+ print(result)
165
+ ```
166
+
167
+ ## Training Details
168
+
169
+ ### Training Data
170
+
171
+ - **Source**: Public Terraform Registry documentation
172
+ - **Data Type**: Terraform configuration files and documentation
173
+ - **Preprocessing**: Standard text preprocessing with sequence length of 512 tokens
174
+
175
+ ### Training Procedure
176
+
177
+ - **Method**: QLoRA (4-bit quantization + LoRA)
178
+ - **LoRA Rank**: 64
179
+ - **LoRA Alpha**: 16
180
+ - **Target Modules**: q_proj, v_proj
181
+ - **Training Epochs**: 3
182
+ - **Max Sequence Length**: 512
183
+ - **Quantization**: 4-bit (fp4)
184
+
185
+ ### Training Hyperparameters
186
+
187
+ - **Training regime**: 4-bit mixed precision
188
+ - **LoRA Dropout**: 0.0
189
+ - **Learning Rate**: Optimized for QLoRA training
190
+ - **Batch Size**: Optimized for memory efficiency
191
+
192
+ ## Limitations and Bias
193
+
194
+ ### Known Limitations
195
+
196
+ - **Context Length**: Limited to 512 tokens due to training configuration
197
+ - **Domain Specificity**: Optimized for Terraform, may not perform well on other infrastructure tools
198
+ - **Base Model Limitations**: Inherits limitations from CodeLlama-7b-Instruct-hf
199
+
200
+ ### Recommendations
201
+
202
+ - Use for Terraform-specific tasks only
203
+ - Validate generated configurations before deployment
204
+ - Consider the 512-token context limit for complex configurations
205
+ - For production use, always review and test generated code
206
+
207
+ ## Environmental Impact
208
+
209
+ - **Training Method**: QLoRA reduces computational requirements significantly
210
+ - **Hardware**: Trained using efficient 4-bit quantization
211
+ - **Carbon Footprint**: Reduced compared to full fine-tuning due to QLoRA efficiency
212
+
213
+ ## Citation
214
+
215
+ If you use this model in your research, please cite:
216
+
217
+ ```bibtex
218
+ @misc{terraform-codellama-7b,
219
+ title={terraform-codellama-7b: A LoRA Fine-tuned Model for Terraform Code Generation},
220
+ author={Rafi Al Attrach and Patrick Schmitt and Nan Wu and Helena Schneider and Stefania Saju},
221
+ year={2024},
222
+ url={https://huggingface.co/rafiaa/terraform-codellama-7b}
223
+ }
224
+ ```
225
+
226
+ ## Related Models
227
+
228
+ - **Base Model**: [codellama/CodeLlama-7b-Instruct-hf](https://huggingface.co/codellama/CodeLlama-7b-Instruct-hf)
229
+ - **Enhanced Version**: [rafiaa/terraform-cloud-codellama-7b](https://huggingface.co/rafiaa/terraform-cloud-codellama-7b) (Recommended - includes cloud provider documentation)
230
+
231
+ ## Model Card Contact
232
+
233
+ - **Author**: rafiaa
234
+ - **Model Repository**: [HuggingFace Model](https://huggingface.co/rafiaa/terraform-codellama-7b)
235
+ - **Issues**: Please report issues through the HuggingFace model page
236
+
237
+ ---
238
+
239
+ *This model is part of a research project conducted in early 2024, focusing on specialized code generation for infrastructure-as-code tools.*
adapter_config.json ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alpha_pattern": {},
3
+ "auto_mapping": null,
4
+ "base_model_name_or_path": "codellama/CodeLlama-7b-Instruct-hf",
5
+ "bias": "none",
6
+ "fan_in_fan_out": false,
7
+ "inference_mode": true,
8
+ "init_lora_weights": true,
9
+ "layers_pattern": null,
10
+ "layers_to_transform": null,
11
+ "loftq_config": {},
12
+ "lora_alpha": 16,
13
+ "lora_dropout": 0.0,
14
+ "megatron_config": null,
15
+ "megatron_core": "megatron.core",
16
+ "modules_to_save": null,
17
+ "peft_type": "LORA",
18
+ "r": 64,
19
+ "rank_pattern": {},
20
+ "revision": null,
21
+ "target_modules": [
22
+ "q_proj",
23
+ "v_proj"
24
+ ],
25
+ "task_type": "CAUSAL_LM"
26
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cea474d825b4c72d43efbc03a1996e31d756f40a3a29403e534e92b8b23e3446
3
+ size 134235048
gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "▁<PRE>",
4
+ "▁<MID>",
5
+ "▁<SUF>",
6
+ "▁<EOT>"
7
+ ],
8
+ "bos_token": {
9
+ "content": "<s>",
10
+ "lstrip": false,
11
+ "normalized": true,
12
+ "rstrip": false,
13
+ "single_word": false
14
+ },
15
+ "eos_token": {
16
+ "content": "</s>",
17
+ "lstrip": false,
18
+ "normalized": true,
19
+ "rstrip": false,
20
+ "single_word": false
21
+ },
22
+ "pad_token": "</s>",
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": true,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<unk>",
5
+ "lstrip": false,
6
+ "normalized": true,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<s>",
13
+ "lstrip": false,
14
+ "normalized": true,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": true,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "32007": {
28
+ "content": "▁<PRE>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "32008": {
36
+ "content": "▁<SUF>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "32009": {
44
+ "content": "▁<MID>",
45
+ "lstrip": false,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ },
51
+ "32010": {
52
+ "content": "▁<EOT>",
53
+ "lstrip": false,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": true
58
+ }
59
+ },
60
+ "additional_special_tokens": [
61
+ "▁<PRE>",
62
+ "▁<MID>",
63
+ "▁<SUF>",
64
+ "▁<EOT>"
65
+ ],
66
+ "bos_token": "<s>",
67
+ "clean_up_tokenization_spaces": false,
68
+ "eos_token": "</s>",
69
+ "eot_token": "▁<EOT>",
70
+ "fill_token": "<FILL_ME>",
71
+ "legacy": null,
72
+ "middle_token": "▁<MID>",
73
+ "model_max_length": 1000000000000000019884624838656,
74
+ "pad_token": "</s>",
75
+ "prefix_token": "▁<PRE>",
76
+ "sp_model_kwargs": {},
77
+ "suffix_token": "▁<SUF>",
78
+ "tokenizer_class": "CodeLlamaTokenizer",
79
+ "unk_token": "<unk>",
80
+ "use_default_system_prompt": false
81
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ce6b411763930e5bf203e954f08621cbe7096f1c46a4cb8ab58844d94b69172
3
+ size 4600