File size: 4,773 Bytes
4c1ce24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: apache-2.0
base_model: Qwen/Qwen2.5-Coder-7B-Instruct
tags:
  - finops
  - aws
  - terraform
  - cdk
  - cloudformation
  - iac
  - qlora
  - unsloth
language:
  - en
pipeline_tag: text-generation
library_name: transformers
---

# FinoCode-7B β€” The IaC Specialist of the FinOptix family

**FinoCode-7B** is the infrastructure-as-code specialist of the [FinOptix model family](https://huggingface.co/ccortezb). Fine-tuned on **Qwen 2.5 Coder 7B**, it audits and generates **Terraform, AWS CDK (TypeScript & Python), and CloudFormation** with FinOps best practices baked in β€” rightsizing, mandatory tags, Graviton, lifecycle policies, encryption.

Where **[FinOptix-14B](https://huggingface.co/ccortezb/FinOptix-14B-v2)** is the full FinOps architect (cost analysis, architecture graph, dbt, incident triage), **FinoCode-7B writes and fixes the actual IaC code** β€” it's built on a *Coder* base precisely for that.

- **16-bit model:** `ccortezb/FinoCode-7B` (this repo)
- **GGUF (Ollama / llama.cpp):** [`ccortezb/FinoCode-7B-GGUF`](https://huggingface.co/ccortezb/FinoCode-7B-GGUF) β€” Q4_K_M (~4.7GB) and Q6_K (~6.3GB)

---

## What it does

| Capability | Detail |
|-----------|--------|
| **Terraform** | Audit + refactor + generation (rightsizing, Graviton, gp2β†’gp3, S3 lifecycle, RDS, tags) |
| **AWS CDK (TypeScript)** | Audit constructs + generate cost-optimal ones (ARM64, log retention, PAY_PER_REQUEST) |
| **AWS CDK (Python)** | Same, Python-native (EC2 Graviton, S3 lifecycle, tags) |
| **CloudFormation** | YAML audit + corrected templates (EC2, S3, Lambda, RDS, ECS Fargate, SQS DLQ) |

Every recommendation follows the FinOps framework (Inform β†’ Optimize β†’ Operate) and outputs valid, properly-indented code.

---

## Training

| Parameter | Value |
|-----------|-------|
| Base model | `Qwen/Qwen2.5-Coder-7B-Instruct` (4-bit via Unsloth) |
| Method | QLoRA (r=16, Ξ±=32, dropout=0.05) |
| Framework | Unsloth + TRL (SFTTrainer) |
| Dataset | **400 examples** IaC-heavy (200 Terraform + 100 CloudFormation + 60 CDK TS + 40 CDK Python) |
| Hardware | Modal A100-80GB |
| Duration | ~3 minutes, 3 epochs, 75 steps |
| Final train loss | 0.47 |
| Cost | ~$0.30 |

The dataset was built with deterministic generators faithful to real-world IaC patterns β€” 100% of examples contain valid code blocks.

---

## Usage

### Transformers

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained("ccortezb/FinoCode-7B", device_map="auto")
tok = AutoTokenizer.from_pretrained("ccortezb/FinoCode-7B")

messages = [
    {"role": "system", "content": "You are FinoCode-7B, the IaC specialist of the FinOptix family. Output valid code."},
    {"role": "user", "content": "Generate a cost-optimal AWS CDK (TypeScript) DynamoDB table with on-demand billing and encryption."},
]
inputs = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
out = model.generate(inputs, max_new_tokens=350, do_sample=False, repetition_penalty=1.1)
print(tok.decode(out[0][inputs.shape[1]:], skip_special_tokens=True))
```

### Ollama (GGUF)

```bash
ollama run hf.co/ccortezb/FinoCode-7B-GGUF:Q4_K_M
# higher fidelity:
ollama run hf.co/ccortezb/FinoCode-7B-GGUF:Q6_K
```

Requires ~5GB RAM/VRAM (Q4_K_M) or ~7GB (Q6_K) β€” runs comfortably on a laptop.

---

## Example tasks

**CDK Python audit** β†’ flags a `m5.4xlarge` with no tags, returns corrected Python with Graviton (`m6g`) + `Tags.of(...)`.

**CloudFormation audit** β†’ flags missing tags + x86 instance, returns corrected YAML with Graviton (`m6g.large`) and a `Tags` block.

**Generation** β†’ produces cost-optimal constructs: DynamoDB `PAY_PER_REQUEST`, S3 lifecycle (IA β†’ Glacier β†’ expire), Lambda on ARM64 with 2-week log retention, SQS with a dead-letter queue.

---

## The FinOptix family

| Model | Base | Specialty |
|-------|------|-----------|
| [FinOptix-14B v2](https://huggingface.co/ccortezb/FinOptix-14B-v2) | Qwen 2.5 14B | Full FinOps architect (cost, graph, dbt, incidents) |
| **FinoCode-7B** (this) | Qwen 2.5 Coder 7B | **IaC audit + generation** |

Use case: IDE copilot for IaC, PR review bot, CI pipeline IaC optimizer.

---

## Limitations

- Trained on synthetic data modeled after real patterns β€” no customer data.
- Generates and audits IaC; does not deploy or call live AWS APIs.
- Cost figures are illustrative unless real metrics are provided.
- v0.1 β€” Terraform + CDK (TS/Py) + CloudFormation. Pulumi / Terraform CDK / multi-cloud are future work.

## License

Apache-2.0. Built by **Carlos Cortez** β€” AWS Community Hero.
[LinkedIn](https://www.linkedin.com/in/carloscortezcloud) Β· [X](https://x.com/ccortezb) Β· [GitHub](https://github.com/ccortezb)