rafiaa commited on
Commit
81148b8
Β·
verified Β·
1 Parent(s): fa76515

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,295 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ - aws
18
+ - azure
19
+ - gcp
20
+ - multi-cloud
21
+ - automation
22
+ - configuration-management
23
+ - cloud-infrastructure
24
+ license: apache-2.0
25
+ language:
26
+ - en
27
+ pipeline_tag: text-generation
28
+ ---
29
+
30
+ # terraform-cloud-codellama-7b
31
+
32
+ **RECOMMENDED MODEL** - An advanced LoRA fine-tuned model for comprehensive Terraform infrastructure-as-code generation, supporting multiple cloud providers (AWS, Azure, GCP). This model generates Terraform configurations, HCL code, and multi-cloud infrastructure automation scripts.
33
+
34
+ ## Model Description
35
+
36
+ This is the **enhanced model** - an advanced version of terraform-codellama-7b that has been additionally trained on AWS, Azure, and GCP public documentation. It provides superior performance for multi-cloud Terraform development with deep understanding of cloud provider-specific resources and best practices.
37
+
38
+ ### Key Features
39
+
40
+ - **Multi-Cloud Support**: Trained on AWS, Azure, and GCP documentation
41
+ - **Enhanced Performance**: Superior to the base terraform-codellama-7b model
42
+ - **Production Ready**: Optimized for real-world multi-cloud infrastructure development
43
+ - **Comprehensive Coverage**: Handles complex cloud provider-specific configurations
44
+ - **Efficient Training**: Uses QLoRA (4-bit quantization + LoRA) for memory efficiency
45
+
46
+ ## Model Details
47
+
48
+ - **Developed by**: Rafi Al Attrach, Patrick Schmitt, Nan Wu, Helena Schneider, Stefania Saju (TUM + IBM Research Project)
49
+ - **Model type**: LoRA fine-tuned CodeLlama (Enhanced)
50
+ - **Language(s)**: English
51
+ - **License**: Apache 2.0
52
+ - **Finetuned from**: [codellama/CodeLlama-7b-Instruct-hf](https://huggingface.co/codellama/CodeLlama-7b-Instruct-hf)
53
+ - **Training method**: QLoRA (4-bit quantization + LoRA)
54
+ - **Base Model**: Built on [rafiaa/terraform-codellama-7b](https://huggingface.co/rafiaa/terraform-codellama-7b)
55
+
56
+ ### Technical Specifications
57
+
58
+ - **Base Model**: CodeLlama-7b-Instruct-hf
59
+ - **LoRA Rank**: 64
60
+ - **LoRA Alpha**: 16
61
+ - **Target Modules**: q_proj, v_proj
62
+ - **Training Epochs**: 3 (Stage 1) + Additional training (Stage 2)
63
+ - **Max Sequence Length**: 512
64
+ - **Quantization**: 4-bit (fp4)
65
+
66
+ ## Uses
67
+
68
+ ### Direct Use
69
+
70
+ This model is designed for:
71
+ - **Multi-cloud Terraform development**
72
+ - **AWS resource configuration** (EC2, S3, RDS, Lambda, etc.)
73
+ - **Azure resource management** (Virtual Machines, Storage Accounts, App Services, etc.)
74
+ - **GCP resource deployment** (Compute Engine, Cloud Storage, Cloud SQL, etc.)
75
+ - **Complex infrastructure orchestration**
76
+ - **Cloud provider-specific best practices**
77
+
78
+ ### Example Use Cases
79
+
80
+ ```python
81
+ # Generate AWS multi-service infrastructure
82
+ prompt = "Create a Terraform configuration for an AWS application with VPC, EC2, RDS, and S3"
83
+ ```
84
+
85
+ ```python
86
+ # Generate Azure App Service with database
87
+ prompt = "Create a Terraform configuration for an Azure App Service with PostgreSQL database"
88
+ ```
89
+
90
+ ```python
91
+ # Generate GCP Kubernetes cluster
92
+ prompt = "Create a Terraform configuration for a GCP GKE cluster with node pools"
93
+ ```
94
+
95
+ ```python
96
+ # Generate multi-cloud setup
97
+ prompt = "Create a Terraform configuration for a hybrid cloud setup using AWS and Azure"
98
+ ```
99
+
100
+ ## How to Get Started
101
+
102
+ ### Installation
103
+
104
+ ```bash
105
+ pip install transformers torch peft accelerate bitsandbytes
106
+ ```
107
+
108
+ ### Loading the Model
109
+
110
+ #### GPU Usage (Recommended)
111
+ ```python
112
+ from transformers import AutoTokenizer, AutoModelForCausalLM
113
+ from peft import PeftModel
114
+ import torch
115
+
116
+ # Load base model with 4-bit quantization (GPU)
117
+ base_model = "codellama/CodeLlama-7b-Instruct-hf"
118
+ model = AutoModelForCausalLM.from_pretrained(
119
+ base_model,
120
+ load_in_4bit=True,
121
+ torch_dtype=torch.float16,
122
+ device_map="auto"
123
+ )
124
+
125
+ # Load LoRA adapter
126
+ model = PeftModel.from_pretrained(model, "rafiaa/terraform-cloud-codellama-7b")
127
+ tokenizer = AutoTokenizer.from_pretrained(base_model)
128
+
129
+ # Set pad token
130
+ if tokenizer.pad_token is None:
131
+ tokenizer.pad_token = tokenizer.eos_token
132
+ ```
133
+
134
+ #### CPU Usage (Alternative)
135
+ ```python
136
+ from transformers import AutoTokenizer, AutoModelForCausalLM
137
+ from peft import PeftModel
138
+ import torch
139
+
140
+ # Load base model (CPU compatible)
141
+ base_model = "codellama/CodeLlama-7b-Instruct-hf"
142
+ model = AutoModelForCausalLM.from_pretrained(
143
+ base_model,
144
+ torch_dtype=torch.float32,
145
+ device_map="cpu"
146
+ )
147
+
148
+ # Load LoRA adapter
149
+ model = PeftModel.from_pretrained(model, "rafiaa/terraform-cloud-codellama-7b")
150
+ tokenizer = AutoTokenizer.from_pretrained(base_model)
151
+
152
+ # Set pad token
153
+ if tokenizer.pad_token is None:
154
+ tokenizer.pad_token = tokenizer.eos_token
155
+ ```
156
+
157
+ ### Usage Example
158
+
159
+ ```python
160
+ def generate_terraform(prompt, max_length=512):
161
+ inputs = tokenizer(prompt, return_tensors="pt")
162
+
163
+ with torch.no_grad():
164
+ outputs = model.generate(
165
+ **inputs,
166
+ max_length=max_length,
167
+ temperature=0.7,
168
+ do_sample=True,
169
+ pad_token_id=tokenizer.eos_token_id
170
+ )
171
+
172
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
173
+
174
+ # Example: Multi-cloud infrastructure
175
+ prompt = """
176
+ Create a Terraform configuration for a multi-cloud setup:
177
+ - AWS: VPC with public/private subnets, EC2 instances
178
+ - Azure: Storage account and App Service
179
+ - GCP: Cloud SQL database
180
+ """
181
+
182
+ result = generate_terraform(prompt)
183
+ print(result)
184
+ ```
185
+
186
+ ### Advanced Usage
187
+
188
+ ```python
189
+ # Cloud-specific prompts
190
+ aws_prompt = "Create a Terraform configuration for AWS EKS cluster with managed node groups"
191
+ azure_prompt = "Create a Terraform configuration for Azure Kubernetes Service (AKS)"
192
+ gcp_prompt = "Create a Terraform configuration for GCP Cloud Run service"
193
+
194
+ # Generate configurations
195
+ aws_config = generate_terraform(aws_prompt)
196
+ azure_config = generate_terraform(azure_prompt)
197
+ gcp_config = generate_terraform(gcp_prompt)
198
+ ```
199
+
200
+ ## Training Details
201
+
202
+ ### Training Data
203
+
204
+ **Stage 1**: Public Terraform Registry documentation
205
+ **Stage 2**: Additional training on:
206
+ - **AWS Documentation**: EC2, S3, RDS, Lambda, VPC, IAM, etc.
207
+ - **Azure Documentation**: Virtual Machines, Storage Accounts, App Services, Key Vault, etc.
208
+ - **GCP Documentation**: Compute Engine, Cloud Storage, Cloud SQL, GKE, etc.
209
+
210
+ ### Training Procedure
211
+
212
+ - **Method**: QLoRA (4-bit quantization + LoRA)
213
+ - **Two-Stage Training**:
214
+ 1. Terraform Registry documentation
215
+ 2. Cloud provider documentation (AWS, Azure, GCP)
216
+ - **LoRA Rank**: 64
217
+ - **LoRA Alpha**: 16
218
+ - **Target Modules**: q_proj, v_proj
219
+ - **Training Epochs**: 3 (Stage 1) + Additional training (Stage 2)
220
+ - **Max Sequence Length**: 512
221
+ - **Quantization**: 4-bit (fp4)
222
+
223
+ ### Training Hyperparameters
224
+
225
+ - **Training regime**: 4-bit mixed precision
226
+ - **LoRA Dropout**: 0.0
227
+ - **Learning Rate**: Optimized for QLoRA training
228
+ - **Batch Size**: Optimized for memory efficiency
229
+
230
+ ## Performance Comparison
231
+
232
+ | Model | Terraform Knowledge | AWS Support | Azure Support | GCP Support | Multi-Cloud Capability |
233
+ |-------|-------------------|-------------|---------------|-------------|-------------------|
234
+ | terraform-codellama-7b | Excellent | Limited | Limited | Limited | Basic |
235
+ | **terraform-cloud-codellama-7b** | Excellent | Excellent | Excellent | Excellent | Advanced |
236
+
237
+ ## Limitations and Bias
238
+
239
+ ### Known Limitations
240
+
241
+ - **Context Length**: Limited to 512 tokens due to training configuration
242
+ - **Domain Specificity**: Optimized for Terraform and cloud infrastructure
243
+ - **Base Model Limitations**: Inherits limitations from CodeLlama-7b-Instruct-hf
244
+ - **Cloud Provider Updates**: May not include the latest cloud provider features
245
+
246
+ ### Recommendations
247
+
248
+ - Use for Terraform and cloud infrastructure tasks
249
+ - Validate generated configurations before deployment
250
+ - Consider the 512-token context limit for complex configurations
251
+ - For production use, always review and test generated code
252
+ - Stay updated with cloud provider documentation for latest features
253
+
254
+ ## Environmental Impact
255
+
256
+ - **Training Method**: QLoRA reduces computational requirements significantly
257
+ - **Hardware**: Trained using efficient 4-bit quantization
258
+ - **Carbon Footprint**: Reduced compared to full fine-tuning due to QLoRA efficiency
259
+ - **Two-Stage Approach**: Efficient incremental training
260
+
261
+ ## Citation
262
+
263
+ If you use this model in your research, please cite:
264
+
265
+ ```bibtex
266
+ @misc{terraform-cloud-codellama-7b,
267
+ title={terraform-cloud-codellama-7b: A Multi-Cloud LoRA Fine-tuned Model for Terraform Code Generation},
268
+ author={Rafi Al Attrach and Patrick Schmitt and Nan Wu and Helena Schneider and Stefania Saju},
269
+ year={2024},
270
+ url={https://huggingface.co/rafiaa/terraform-cloud-codellama-7b}
271
+ }
272
+ ```
273
+
274
+ ## Related Models
275
+
276
+ - **Base Model**: [codellama/CodeLlama-7b-Instruct-hf](https://huggingface.co/codellama/CodeLlama-7b-Instruct-hf)
277
+ - **Stage 1 Model**: [rafiaa/terraform-codellama-7b](https://huggingface.co/rafiaa/terraform-codellama-7b)
278
+ - **This Model**: [rafiaa/terraform-cloud-codellama-7b](https://huggingface.co/rafiaa/terraform-cloud-codellama-7b) (Recommended)
279
+
280
+ ## Model Card Contact
281
+
282
+ - **Author**: rafiaa
283
+ - **Model Repository**: [HuggingFace Model](https://huggingface.co/rafiaa/terraform-cloud-codellama-7b)
284
+ - **Issues**: Please report issues through the HuggingFace model page
285
+
286
+ ## Acknowledgments
287
+
288
+ - **Research Project**: Early 2024 research project at TUM + IBM
289
+ - **Training Data**: Public documentation from Terraform Registry, AWS, Azure, and GCP
290
+ - **Base Model**: Meta's CodeLlama-7b-Instruct-hf
291
+ - **Training Method**: QLoRA for efficient fine-tuning
292
+
293
+ ---
294
+
295
+ *This model represents the culmination of a two-stage fine-tuning approach, combining Terraform expertise with comprehensive cloud provider knowledge for superior infrastructure-as-code generation.*
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
+ "v_proj",
23
+ "q_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:5ceed0c4c770992a0c222605208186092c792755c980836cab1628bf9988bee0
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:9d6d743a5ea448e88622f69d8ee718438fcd05eddbd451faf76bb807b13a295a
3
+ size 4600