Docs / Training TensorFlow models from C++ / `_AI`
Training TensorFlow models from C++ / _AI
Short answer
You generally do not train full TensorFlow/Keras models inside C++.
The supported training stack is Python. The C API (tensorflow/c/c_api.h) is built for loading SavedModels and running sessions (what _TFServe already does).
From _AI, the practical ways are:
| Profile | What runs in C++ | What actually trains |
|---|---|---|
pipeline |
Job spawn + tracking | Python under tensorflow_training/* |
finetune |
TF_SessionRun on a train signature |
Graph already baked in SavedModel |
native |
Hand-rolled GD / MathNN | Not TensorFlow — small tabular demos |
mock |
Dry-run job records | Nothing |
Commands
tftrain ways # full explanation
tftrain doctor
tftrain profile pipeline|finetune|native|mock
tftrain dry-run on|off
tftrain pipeline fonts|road_signs|text|coco_stuff|firearms|league|all
tftrain finetune <model> [steps] [feat_dim] [label_dim]
tftrain native [csv] [steps] [lr]
tftrain jobs
tftrain selftest
Recommended production path
1. Prepare data + train in Python (tensorflow_training/.../run_*.ps1)
2. Export SavedModel (and optional TFLite)
3. Place under third_party/tf_models/<name> or configured path
4. tf / tfmodel load + serve via TFServe C API
Optional: in-process fine-tune
Export from Python a SavedModel that includes a train signature, e.g. inputs x,y → loss, with optimizer variables inside the graph. Then:
tftrain profile finetune
tftrain dry-run off
tftrain finetune my_trainable_model 100 32 1
This calls _TFModels::FineTuneStep → _TFServe::Run.
Why not “pure C++ TF training”?
- TensorFlow 2 training is Keras / Python-first.
- The old TF1 C++ training API is not a maintained product path for modern models.
- Building graphs, datasets, and distribution strategies in C++ is unsupported friction for almost no gain versus: Python train → C++ serve.
Native C++ alternative
For baselines without TF:
tftrain profile native
tftrain dry-run off
tftrain native 500 0.05 # synthetic linear
tftrain native data/set.csv 300 0.01
CSV: numeric columns, last column = label.
Env
| Variable | Meaning |
|---|---|
AI_TF_PYTHON |
Python executable |
AI_TF_TRAIN_ROOT |
Default tensorflow_training |
AI_TF_TRAIN_PROFILE |
mock / pipeline / … |
AI_TF_TRAIN_DRY_RUN |
Default on |
Files
TFTrain.hpp/TFTrain.cpp— orchestrationTFModels::FineTuneStep— C API train-signature steptensorflow_training/— existing Python GPU pipelines
Generated from the project markdown docs on 2026-07-24. This is a static, self-contained site.