Downloads · 30 days
9
10% of all-time downloads
rafiaa/terraform-codellama-7b
terraform-codellama-7b is a text generation model from rafiaa. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
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)…
Downloads · 30 days
9
10% of all-time downloads
All-time downloads
92
Public
Repo size
134 MB
Likes
0
Public
Click a slice to open those files.
.safetensors134 MB · 99%
From the Hugging Face model README
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.
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.
This model is designed for:
# Generate AWS EC2 instance configuration
prompt = "Create a Terraform configuration for an AWS EC2 instance with t3.medium instance type"
# Generate Azure resource group
prompt = "Create a Terraform configuration for an Azure resource group in West Europe"
# Generate GCP compute instance
prompt = "Create a Terraform configuration for a GCP compute instance with Ubuntu 20.04"
pip install transformers torch peft accelerate bitsandbytes
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
# Load base model with 4-bit quantization (GPU)
base_model = "codellama/CodeLlama-7b-Instruct-hf"
model = AutoModelForCausalLM.from_pretrained(
base_model,
load_in_4bit=True,
torch_dtype=torch.float16,
device_map="auto"
)
# Load LoRA adapter
model = PeftModel.from_pretrained(model, "rafiaa/terraform-codellama-7b")
tokenizer = AutoTokenizer.from_pretrained(base_model)
# Set pad token
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
# Load base model (CPU compatible)
base_model = "codellama/CodeLlama-7b-Instruct-hf"
model = AutoModelForCausalLM.from_pretrained(
base_model,
torch_dtype=torch.float32,
device_map="cpu"
)
# Load LoRA adapter
model = PeftModel.from_pretrained(model, "rafiaa/terraform-codellama-7b")
tokenizer = AutoTokenizer.from_pretrained(base_model)
# Set pad token
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token
def generate_terraform(prompt, max_length=512):
inputs = tokenizer(prompt, return_tensors="pt")
with torch.no_grad():
outputs = model.generate(
**inputs,
max_length=max_length,
temperature=0.7,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
return tokenizer.decode(outputs[0], skip_special_tokens=True)
# Example usage
prompt = "Create a Terraform configuration for an AWS S3 bucket with versioning enabled"
result = generate_terraform(prompt)
print(result)
If you use this model in your research, please cite:
@misc{terraform-codellama-7b,
title={terraform-codellama-7b: A LoRA Fine-tuned Model for Terraform Code Generation},
author={Rafi Al Attrach and Patrick Schmitt and Nan Wu and Helena Schneider and Stefania Saju},
year={2024},
url={https://huggingface.co/rafiaa/terraform-codellama-7b}
}
This model is part of a research project conducted in early 2024, focusing on specialized code generation for infrastructure-as-code tools.