Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor training loop from script to class #35

Closed
wants to merge 2 commits into from

Conversation

sweep-nightly[bot]
Copy link

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

Description

This PR refactors the training loop from a script to a class in order to improve code modularity and maintainability. The training loop is encapsulated in a new class called Trainer in the main.py file. The Trainer class has methods for training a single epoch, evaluating the model, and running the entire training process. The api.py file is also updated to import the Trainer class instead of the Net class.

Summary of Changes

  • Created a new class Trainer in main.py to encapsulate the training loop.
  • Added attributes model, optimizer, criterion, and dataloader to the Trainer class.
  • Implemented the train_epoch method in the Trainer class to perform training for a single epoch.
  • Implemented the evaluate method in the Trainer class to evaluate the model on the training data.
  • Implemented the train method in the Trainer class to run the entire training process.
  • Updated the import statement in api.py to import the Trainer class instead of the Net class.
  • Updated the code in api.py to create an instance of the Trainer class and access its model attribute.

Please review and merge this PR. Thank you!

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 13, 2023

Rollback Files For Sweep

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

@sweep-nightly
Copy link
Author

sweep-nightly bot commented Oct 13, 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.

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
1 participant