Template Generation System
The Cirron CLI uses a modular template generation system that produces framework-specific project code based on your chosen template and model type. This page covers how the system works internally and how to extend it. For per-framework details, see PyTorch, TensorFlow, and scikit-learn.Available templates
| Template | Description |
|---|---|
pytorch | PyTorch inference |
pytorch-train | PyTorch training pipeline |
tensorflow | TensorFlow inference |
tensorflow-train | TensorFlow training pipeline |
sklearn | Basic scikit-learn model |
sklearn-pipeline | Full scikit-learn pipeline |
custom | Blank Python project |
How generation works
When you runcirron init, the CLI:
- Selects the template you specified.
- Calls
createCommonMLFiles()to write the shared scaffolding (Dockerfile, requirements.txt, README,cirron.yaml, tests,.gitignore,.env.example). See Common files. - Calls the framework-specific generator (e.g.
createPyTorchFiles()) to writesrc/model.py,src/data_loader.py,src/inference.py, and, for*-traintemplates,src/train.py. - Resolves the model architecture and data loader bodies via two helpers:
getModelCode(framework, modelType): returns the source forsrc/model.py.getDataLoaderCode(framework, modelType): returns the source forsrc/data_loader.py.
- Writes everything to disk and prints next steps.
File layout in the CLI source
Template generation lives undersrc/commands/files/ in the CLI repo:
(projectPath, projectName, options) => Promise<void>. They write files to disk and return nothing, making them easy to test and compose.
Model types
getModelCode() and getDataLoaderCode() switch on modelType:
classification: Cross-entropy loss, softmax output. PyTorch/TensorFlow generate a small MLP or CNN; sklearn usesRandomForestClassifier.regression: MSE loss, linear output. PyTorch/TensorFlow generate an MLP; sklearn usesRandomForestRegressor.computer_vision: Conv-based architecture (PyTorchnn.Conv2dstack, TensorFlowConv2Dstack).custom: Skipped; you writesrc/model.pyyourself.
Extending the system
Adding a new model type
- Add a branch in
getModelCode():
- Add the matching branch in
getDataLoaderCode(). - Add the model type to the interactive prompt list in
src/commands/init.ts.
Adding a new framework
- Create
src/commands/files/<framework>.tsexporting acreate<Framework>Files()function. - Add framework-specific branches in
getModelCode()andgetDataLoaderCode(). - Register the template name(s) in the
initcommand’s template registry. - Add a docs page under
apps/docs/cli/templates/.
Generation entry point
The high-level call looks like:Best practices for authoring templates
- Match the runtime contract: generated
src/inference.pymust expose aModelInferenceclass withpredict(input). The Cirron runtime imports it by name. - Wire the SDK: generated training and inference code should import
cirron as ciand callci.profile()once at module top so traces flow tocirron traces. Useci.scope("name")for explicit regions andci.wrap(estimator)for scikit-learn models. - Provide sensible defaults: model hyperparameters, batch size, learning rate should work on the bundled sample data without tweaking.
- Fail soft on missing data: fall back to
data/sample/sample_data.csvif the user’s data path is empty. - Pin loose dependency versions:
>=X.Y.0for the framework, exact for security-sensitive libs.
Next Steps
PyTorch Template
Deep learning with PyTorch
TensorFlow Template
Deep learning with TensorFlow
scikit-learn Template
Traditional ML algorithms
Common files
Shared scaffolding for every template