Skip to content

Training Workflow

Sudhanshu edited this page Nov 11, 2026 · 1 revision

Training, Validation, and Test Workflow

flowchart TD
    Start(["CLI selects mode and config"]) --> Source["Load synthetic or Yelp samples"]
    Source --> Data["Build train / validation / test DataLoaders"]
    Data --> Init["Initialize custom TransformerClassifier"]
    Init --> Optim["Initialize AdamW optimizer"]
    Optim --> Epoch["Train epoch"]
    Epoch --> Loss["Cross-entropy loss + backward"]
    Loss --> Clip["Clip gradient norm to 1.0"]
    Clip --> Step["Optimizer step over batches"]
    Step --> Val["Evaluate validation split"]
    Val --> Improve{"Validation accuracy improved?"}
    Improve -->|Yes| Save["Save best_transformer_static_emb.pt"]
    Improve -->|No| Next{"More epochs?"}
    Save --> Next
    Next -->|Yes| Epoch
    Next -->|No| Reload["Reload best checkpoint (weights_only=True)"]
    Reload --> Test["Evaluate held-out test split once"]
    Test --> Done(["Print final metrics"])
Loading

Training operations

  • Optimizer: torch.optim.AdamW(model.parameters(), lr=args.lr, weight_decay=0.01).
  • Loss: cross-entropy over two logits with integer labels.
  • Gradient clipping: global norm at 1.0 before the optimizer step.
  • Metrics: per-epoch training loss and accuracy, validation loss and accuracy.
  • Best-model selection: save a checkpoint only when validation accuracy strictly improves.
  • Final evaluation: reload best checkpoint and calculate metrics on test split once.

Reproducibility boundaries

The program seeds Python random and torch.manual_seed, but it does not fully enforce deterministic CUDA operations or seed all DataLoader/GPU sources. Dataset sampling uses fixed seeds 42 and 43. Report real metrics with hardware, package versions, data sizes and seeds.

Runtime characteristics

  • Uses one local process with PyTorch DataLoaders (num_workers=0).
  • Selects a single available CUDA GPU for real-data modes, otherwise CPU; smoke mode always uses CPU.
  • The --full preset can require significant memory and training time; it overrides several CLI settings.
  • No scheduler, distributed training, mixed-precision training or automated experiment tracker is implemented.

Clone this wiki locally