> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cirron.com/llms.txt
> Use this file to discover all available pages before exploring further.

# compile

> Compile and optimize models for production serving.

# cirron compile

Compile your ML models for production deployment with architecture-specific optimizations and validation.

## Usage

```bash theme={null}
cirron compile [options]
```

## Options

| Option              | Description                                           | Default       |
| ------------------- | ----------------------------------------------------- | ------------- |
| `--arch, -a`        | Target architecture (`cpu`, `cuda`, `gpu`)            | Auto-detected |
| `--index`           | Path to index/manifest file (JSON or YAML)            | `null`        |
| `--validate`        | Run pre-compilation validation                        | `false`       |
| `--strict`          | Fail fast on validation errors with detailed messages | `false`       |
| `-i, --interactive` | Step-by-step compilation confirmations                | `false`       |

## Architecture and Framework Support

| Architecture | Frameworks                        | Notes                                        |
| ------------ | --------------------------------- | -------------------------------------------- |
| `cpu`        | PyTorch, TensorFlow, Scikit-learn | Lightweight, compatible with all frameworks  |
| `cuda`       | PyTorch                           | GPU-accelerated, validates CUDA availability |
| `gpu`        | TensorFlow                        | GPU-accelerated, validates GPU availability  |

Compilation reads `src/model.py`, optimizes for the target architecture, and writes:

* PyTorch → `models/model_{arch}.pth`
* TensorFlow → `models/model_{arch}/`
* Scikit-learn → `models/model_{arch}.joblib` (via joblib)

Metadata is written to `artifacts/model_info.json`.

## Validation

With `--validate`, the command verifies required files (`src/model.py`, `requirements.txt`), Python version compatibility, architecture-specific requirements (e.g. CUDA availability), model instantiation, and index file format. Combine with `--strict` to fail on the first issue.

## Index Files

```json theme={null}
{
  "features": ["feature1", "feature2", "feature3"],
  "dataTypes": {
    "feature1": "float",
    "feature2": "int",
    "feature3": "string"
  }
}
```

YAML form is also accepted. Pass with `--index config/index.json` or `--index config/index.yaml`.

## Examples

```bash theme={null}
# Auto-detect architecture
cirron compile

# CPU compilation with validation
cirron compile --arch cpu --validate

# PyTorch with CUDA, strict
cirron compile --arch cuda --strict --validate

# TensorFlow with GPU
cirron compile --arch gpu

# Compile with custom index
cirron compile --validate --index data/index.yaml
```

## Output

```
models/
├── model_cpu.pth          # PyTorch CPU model
├── model_cuda.pth         # PyTorch CUDA model
└── model_gpu              # TensorFlow GPU model

artifacts/
├── model_info.json        # Model metadata
└── index_config.json      # Index configuration (if provided)
```

```json theme={null}
{
  "framework": "pytorch",
  "architecture": "cuda",
  "parameters": 1234567,
  "compilation_time": "2024-01-15T10:30:00Z"
}
```

## Troubleshooting

| Error                                 | Resolution                                                                            |
| ------------------------------------- | ------------------------------------------------------------------------------------- |
| `No cirron.yaml found`                | Run `cirron init <name>` to initialize the project                                    |
| `Required file missing: src/model.py` | Create the model file and verify it imports cleanly                                   |
| `Python 3.9+ required, found 3.7`     | Upgrade Python or update `pythonVersion` in `cirron.yaml`                             |
| `CUDA not available for PyTorch`      | Switch to `--arch cpu`, or install CUDA and verify with `nvidia-smi`                  |
| `Compilation failed`                  | Run `python3 src/model.py` to surface errors; check `pip install -r requirements.txt` |

## Integration

```yaml theme={null}
# GitHub Actions
- name: Compile Model
  run: |
    cirron compile --validate --arch cpu
    cirron compile --validate --arch cuda
```

```dockerfile theme={null}
FROM python:3.9 as compile
COPY . /app
WORKDIR /app
RUN cirron compile --arch cpu

FROM python:3.9-slim
COPY --from=compile /app/models /app/models
COPY --from=compile /app/artifacts /app/artifacts
```
