Skip to content

Conversation

@cwu137
Copy link
Contributor

@cwu137 cwu137 commented Feb 5, 2026

This PR refactors the QVAE training implementation to improve code organization, eliminate duplication, and enhance maintainability. The changes focus on modularizing the training pipeline while preserving all original functionality.

Key Changes:

Pretrained Model Support:

  • Smart model loading: Automatically detects existing pretrained QVAE models
  • Seamless workflow: If qvae_mnist.pth exists, loads weights; otherwise trains from scratch

Enhanced Dataset Support:

  • Multiple MNIST variants: Support for mnist, fashion-mnist, and kmnist datasets
  • Improved error messages: Clear guidance when unsupported datasets are specified

Modular Architecture:

  • Added create_model(): Model creation with consistent parameter handling
  • Added _train_epoch(): Encapsulated single-epoch training logic for QVAE
  • Added _train_mlp_epoch() and _eval_mlp_epoch(): Modular training/evaluation for MLP classifier

Eliminated Code Duplication:

  • train_qvae_with_tsne() and train_qvae() now share the same model creation and training logic

Improved Parameter Management:

  • Explicit weight_decay parameter added to training functions
  • Consistent parameter passing through create_model()
  • Better separation of model configuration from modular training logic

Enhanced Code Readability:

  • Added descriptive docstrings to all new functions
  • Improved progress bar descriptions in tqdm

Maintained Full Backward Compatibility:

  • All existing function signatures remain unchanged
  • Training results and model outputs are identical to previous version
  • All visualization and saving functionalities preserved

@NXDnixiaodong NXDnixiaodong merged commit 2bbba2c into qboson:main Feb 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants