openai / weak-to-strong

MIT License
2.49k stars 302 forks source link

Code refactoring and formatting Improvements #4

Closed EwoutH closed 8 months ago

EwoutH commented 9 months ago

This PR applies consistent formatting with Black, Python 3.7+ syntax updates, whitespace and syntax checks, and code simplification. This improves the readability and maintainability of the codebase and aligns it (pun intended) with current Python best practices.

A pre-commit config is added to ensure these changes can be consistently applied in the future. Ideally, this would be supported by a CI configuration like pre-commit.ci.

Key Changes:

  1. Black formatting: Applied Black formatting with a line length of 100, as specified in pyproject.toml. This standardizes the code style across the project. A line length of 100 was chosen because many files already were formatted to that (approximate) line length, minimizing changes.
  2. Python 3.7+ practices: Updated common.py and other files to use Python 3.7+ syntax. This modernizes the codebase and removes legacy constructs.
  3. Pre-commit checks: Introduced pre-commit hooks to enforce Black formatting and to check for trailing spaces and correct toml and yaml syntax.
  4. Code simplification: Refactored code to be more concise, particularly in Plotting.ipynb and train_weak_to_strong.py. For example, multiline expressions have been simplified for better readability.\

I would advice against squashing when merging, I think it's useful to keep the individual commits.

WuTheFWasThat commented 9 months ago

i'm not sure if we want to try to enforce pre-commit, just want to make it lightweight for people to hack on stuff :)

you'll need to rebase this though since we pushed some other changes, sorry

EwoutH commented 9 months ago

Thanks for getting back! We can decide that later.

I've rebased this PR.