Skip to content

Refactor training loop from script to class#65

Closed
sweep-nightly[bot] wants to merge 3 commits intomainfrom
sweep/refactor-training-loop_8
Closed

Refactor training loop from script to class#65
sweep-nightly[bot] wants to merge 3 commits intomainfrom
sweep/refactor-training-loop_8

Conversation

@sweep-nightly
Copy link

@sweep-nightly sweep-nightly bot commented Oct 15, 2023

Description

This PR refactors the training loop from a script to a class for better organization and reusability. The training loop code was originally located in the src/main.py file and has been moved into a new class named MNISTTrainer. The src/api.py file has also been updated to import and use the new class for prediction.

Summary of Changes

  • Created a new class named MNISTTrainer in src/main.py to encapsulate the training loop functionality.
  • Moved the code for loading and preprocessing the MNIST dataset into a method named load_data in the MNISTTrainer class.
  • Moved the code for defining the PyTorch model into a method named define_model in the MNISTTrainer class.
  • Updated the Net class in src/main.py to accept a trainloader parameter in its constructor and use it for training the model.
  • Updated the script at the bottom of src/main.py to create an instance of MNISTTrainer, call its methods to load the data and define the model, and then pass the loaded data to the Net class for training.
  • Updated the import statement in src/api.py to import the MNISTTrainer class instead of the Net class.
  • Updated the code for loading the model in src/api.py to create an instance of MNISTTrainer, call its methods to load the data and define the model, and then load the model's state from the saved file.
  • Updated the documentation in README.md to reflect the changes in the codebase, specifically explaining the new MNISTTrainer class and how it is used in src/main.py and src/api.py.

Fixes #6.


🎉 Latest improvements to Sweep:

  • Sweep can now passively improve your repository! Check out Rules to learn more.

💡 To get Sweep to edit this pull request, you can:

  • Comment below, and Sweep can edit the entire PR
  • Comment on a file, Sweep will only modify the commented file
  • Edit the original issue to get Sweep to recreate the PR from scratch

@sweep-nightly
Copy link
Author

sweep-nightly bot commented Oct 15, 2023

Rollback Files For Sweep

  • Rollback changes to README.md
  • Rollback changes to src/main.py
  • Rollback changes to src/api.py

@sweep-nightly
Copy link
Author

sweep-nightly bot commented Oct 15, 2023

Apply Sweep Rules to your PR?

  • Apply: All docstrings and comments should be up to date.
  • Apply: Code should be properly formatted and indented.
  • Apply: Variable and function names should be descriptive and follow a consistent naming convention.
  • Apply: Imports should be organized and grouped together.
  • Apply: There should be no unused imports or variables.
  • Apply: Code should be properly commented and include docstrings for functions and classes.

@sweep-nightly sweep-nightly bot added the sweep label Oct 15, 2023
@sweep-nightly sweep-nightly bot closed this Oct 16, 2023
@sweep-nightly sweep-nightly bot deleted the sweep/refactor-training-loop_8 branch October 16, 2023 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sweep: refactor the training loop from a script to a class in main.py

0 participants