Skip to content

Long Training

Run one Hugging Face Transformers training job in consecutive GPU stages. Each stage has its own provider, account, GPU and time limit. When a stage ends, m-gpux can start the next one from the latest uploaded checkpoint. Short scripts still use m-gpux run or m-gpux up.

Set up credentials and a route

Create a private Hugging Face model repository for training artifacts. Log in locally with hf auth login, or set HF_TOKEN in the local environment. Use a write token scoped to that repository. Configure each remote account separately.

  • Modal needs a Modal Secret containing HF_TOKEN. Its default name is hf. Select a different secret with modal_secret.
  • Kaggle needs a dedicated private notebook already linked to a Kaggle secret containing the token. The default secret key is HF_TOKEN. Enable Internet when the notebook's data and usage rules permit it. The configured route replaces that notebook's source with a new worker version. Reserve one notebook per active training run. Keep it private and avoid editing or running it from another session while m-gpux is coordinating it.

Add a training table to mgpux.toml:

[training.finetune]
entrypoint = "train.py:build_trainer"
hub_repo = "your-user/private-training"
max_steps = 1000
segment_minutes = 45
checkpoint_minutes = 10
checkpoint_grace_minutes = 15
idle_minutes = 10
max_cost_usd = 10
route = [
  { backend = "kaggle", account = "your-user", gpu = "T4", kernel = "your-user/mgpux-training" },
  { backend = "modal", account = "work", gpu = "L4" },
  { backend = "modal", account = "work", gpu = "L4" },
]

Each entry gives the worker one GPU. Repeating an entry gives the run another stage on that backend. The preview displays the duration and estimated Modal allocation per stage. The estimated budget includes checkpoint grace time and uses m-gpux's cached or built-in rates. Actual Modal charges vary with measured resource use. The coordinator checks the estimate before each Modal allocation.

m-gpux train start finetune --plan
m-gpux train start finetune
m-gpux runs show RUN_ID

The entrypoint is a single Python source file with a zero-argument factory that returns a configured transformers.Trainer. The worker calls Trainer.train and controls the training output directory, target steps and save schedule. Configure any remaining dependencies with packages. Use fixed dataset and model revisions for a run that needs reproducible resume behavior. See the tiny training example.

Checkpoints, idle shutdown and recovery

The worker saves resumable checkpoints with optimizer, scheduler and RNG state. It uploads the complete checkpoint before recording it as available for recovery. Training metrics and final weights are stored under the same run in the private repository. Metric logs between successful uploads can be lost if a worker is killed. The dashboard shows reported throughput and distinguishes observed steps from the latest uploaded checkpoint.

idle_minutes is the continuous GPU-idle threshold measured inside each worker. Set it to 0 to disable measurement. For idle shutdown or an explicit stop, the worker asks Trainer to save at an optimizer-step boundary and exits after the checkpoint uploads. Give slow uploads enough grace time. A provider timeout, crash or blocked training step can prevent a new checkpoint from being saved.

m-gpux train stop RUN_ID
m-gpux train resume RUN_ID

The Runs dashboard displays route order, progress and checkpoint state. Its Stop safely button sends the same request as the CLI. To add allocations after the route is exhausted, append entries to the original training table and run m-gpux train resume RUN_ID --update-route. You can update the estimated budget at the same time.

Keep the CLI coordinator running while the route is in progress. If it closes, the remote worker can finish its current stage and write artifacts. Resume reattaches to that stage before launching more work. A provider result that cannot be verified leaves the run interrupted for inspection.

Long training stages currently support Modal and Kaggle with one GPU per stage. Colab remains available for one-shot scripts through m-gpux run.