Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
update project (#82)
Browse files Browse the repository at this point in the history
* update
* prune
* ruff
* fixed
* <2.4

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Borda and pre-commit-ci[bot] authored Oct 4, 2024
1 parent bb4f748 commit 7e1e2e8
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 174 deletions.
23 changes: 0 additions & 23 deletions .github/CODEOWNERS

This file was deleted.

39 changes: 0 additions & 39 deletions .github/dependabot.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/ci_install-pkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ jobs:
import-name: "quick_start"
testing-matrix: |
{
"os": ["ubuntu-20.04", "macos-11", "windows-2022"],
"python-version": ["3.8"]
"os": ["ubuntu-22.04", "macos-13", "windows-2022"],
"python-version": ["3.10"]
}
14 changes: 6 additions & 8 deletions .github/workflows/ci_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ concurrency:

jobs:
pytest:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"

- uses: actions/cache@v4
with:
Expand All @@ -27,13 +27,11 @@ jobs:
restore-keys: |
${{ runner.os }}-pip-
- name: Install Lightning
- name: Install packages
run: |
pip install -U lightning -r requirements.txt -r tests/requirements.txt \
pip install -U -r requirements.txt -r tests/requirements.txt \
-f https://download.pytorch.org/whl/cpu/torch_stable.html
pip list
lightning --version
- name: Tests
run: |
python -m pytest tests
run: python -m pytest tests
40 changes: 0 additions & 40 deletions .github/workflows/release-pypi.yml

This file was deleted.

32 changes: 7 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.8
python: python3

ci:
autofix_prs: true
Expand All @@ -21,19 +21,6 @@ repos:
- id: check-docstring-first
- id: detect-private-key

- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py38-plus]
name: Upgrade code

- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
name: Black code

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.17
hooks:
Expand All @@ -43,15 +30,10 @@ repos:
- mdformat-black
- mdformat_frontmatter

- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa

- repo: https://github.com/PyCQA/flake8
rev: 7.1.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.5
hooks:
- id: flake8
args:
- "--max-line-length=120"
- "--ignore=E266"
- id: ruff
args: ["--fix", "--line-length=120", "--target-version=py39"]
- id: ruff-format
args: ["--line-length=120"]
12 changes: 3 additions & 9 deletions quick_start/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def trainer_pre_fn(self, *args, work=None, **kwargs):
return {}, args, kwargs

# 5. Patch the `__init__` method of the Trainer to inject our callback with a reference to the work.
tracer.add_traced(
Trainer, "__init__", pre_fn=partial(trainer_pre_fn, work=self)
)
tracer.add_traced(Trainer, "__init__", pre_fn=partial(trainer_pre_fn, work=self))
return tracer

def run(self, *args, **kwargs):
Expand Down Expand Up @@ -96,9 +94,7 @@ def on_after_run(self, script_globals):
lightning_module = script_globals["cli"].trainer.lightning_module

# 2. From the checkpoint_callback, we are accessing the best model weights
checkpoint = torch.load(
script_globals["cli"].trainer.checkpoint_callback.best_model_path
)
checkpoint = torch.load(script_globals["cli"].trainer.checkpoint_callback.best_model_path)

# 3. Load the best weights and torchscript the model.
lightning_module.load_state_dict(checkpoint["state_dict"])
Expand All @@ -110,9 +106,7 @@ def on_after_run(self, script_globals):
self.best_model_path = Path("model_weight.pt")

# 5. Keep track of the metrics.
self.best_model_score = float(
script_globals["cli"].trainer.checkpoint_callback.best_model_score
)
self.best_model_score = float(script_globals["cli"].trainer.checkpoint_callback.best_model_score)


class ImageServeGradio(ServeGradio):
Expand Down
12 changes: 3 additions & 9 deletions quick_start/setup_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
_PROJECT_ROOT = os.path.dirname(os.path.dirname(__file__))


def _load_requirements(
path_dir: str, file_name: str = "requirements.txt", comment_char: str = "#"
) -> List[str]:
def _load_requirements(path_dir: str, file_name: str = "requirements.txt", comment_char: str = "#") -> List[str]:
"""Load requirements from a file.
>>> _load_requirements(_PROJECT_ROOT) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Expand Down Expand Up @@ -62,13 +60,9 @@ def _load_readme_description(path_dir: str, homepage: str, ver: str) -> str:

# readthedocs badge
text = text.replace("badge/?version=stable", f"badge/?version={ver}")
text = text.replace(
"lightning.readthedocs.io/en/stable/", f"lightning.readthedocs.io/en/{ver}"
)
text = text.replace("lightning.readthedocs.io/en/stable/", f"lightning.readthedocs.io/en/{ver}")
# codecov badge
text = text.replace(
"/branch/master/graph/badge.svg", f"/release/{ver}/graph/badge.svg"
)
text = text.replace("/branch/master/graph/badge.svg", f"/release/{ver}/graph/badge.svg")
# replace github badges for release ones
text = text.replace("badge.svg?branch=master&event=push", f"badge.svg?tag={ver}")

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ gradio <=3.45.2
pyyaml <=6.0.1
protobuf >4.21, <5.28.0 # 4.21 breaks with wandb, tensorboard, or pytorch-lightning: https://github.com/protocolbuffers/protobuf/issues/10048
websockets
lightning[app] >=2.1.0
lightning[app] >=2.1.0, <2.4.0
tensorboard
8 changes: 2 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@


def _load_py_module(fname, pkg=PACKAGE_NAME):
spec = spec_from_file_location(
os.path.join(pkg, fname), os.path.join(_PATH_ROOT, pkg, fname)
)
spec = spec_from_file_location(os.path.join(pkg, fname), os.path.join(_PATH_ROOT, pkg, fname))
py = module_from_spec(spec)
spec.loader.exec_module(py)
return py


about = _load_py_module("__about__.py")
setup_tools = _load_py_module("setup_tools.py")
long_description = setup_tools._load_readme_description(
_PATH_ROOT, homepage=about.__homepage__, ver=about.__version__
)
long_description = setup_tools._load_readme_description(_PATH_ROOT, homepage=about.__homepage__, ver=about.__version__)

# https://packaging.python.org/discussions/install-requires-vs-requirements /
# keep the meta-data here for simplicity in reading this file... it's not obvious
Expand Down
16 changes: 4 additions & 12 deletions train_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,12 @@ def prepare_data(self) -> None:
MNIST("./data", download=True)

def train_dataloader(self):
train_dataset = MNIST(
"./data", train=True, download=False, transform=self.transform
)
return torch.utils.data.DataLoader(
train_dataset, batch_size=self.hparams.batch_size
)
train_dataset = MNIST("./data", train=True, download=False, transform=self.transform)
return torch.utils.data.DataLoader(train_dataset, batch_size=self.hparams.batch_size)

def val_dataloader(self):
val_dataset = MNIST(
"./data", train=False, download=False, transform=self.transform
)
return torch.utils.data.DataLoader(
val_dataset, batch_size=self.hparams.batch_size
)
val_dataset = MNIST("./data", train=False, download=False, transform=self.transform)
return torch.utils.data.DataLoader(val_dataset, batch_size=self.hparams.batch_size)


if __name__ == "__main__":
Expand Down

0 comments on commit 7e1e2e8

Please sign in to comment.