From 0b74a78717b4c922ace39c82bc9554e639504089 Mon Sep 17 00:00:00 2001 From: DocGarbanzo <47540921+DocGarbanzo@users.noreply.github.com> Date: Thu, 15 Dec 2022 20:34:32 +0000 Subject: [PATCH] Upgrade to newest version of pytorch (#1070) * Update to newest version of pytorch: * A couple of interface changes when creating the resnet model, in the Trainer and the model summary * Updated the yaml files to remove pytorch versions * Bumped version --- donkeycar/parts/pytorch/torch_train.py | 21 ++++++++++----------- donkeycar/tests/test_torch.py | 3 +-- install/envs/mac.yml | 6 +++--- install/envs/ubuntu.yml | 6 +++--- install/envs/windows.yml | 6 +++--- setup.py | 6 +++--- 6 files changed, 23 insertions(+), 25 deletions(-) diff --git a/donkeycar/parts/pytorch/torch_train.py b/donkeycar/parts/pytorch/torch_train.py index 3d8a8e812..844b68ade 100644 --- a/donkeycar/parts/pytorch/torch_train.py +++ b/donkeycar/parts/pytorch/torch_train.py @@ -2,6 +2,7 @@ from pathlib import Path import torch import pytorch_lightning as pl +from pytorch_lightning.utilities.model_summary import summarize from donkeycar.parts.pytorch.torch_data import TorchTubDataModule from donkeycar.parts.pytorch.torch_utils import get_model_by_type @@ -16,9 +17,8 @@ def train(cfg, tub_paths, model_output_path, model_type, checkpoint_path=None): if is_torch_model: model = f'{model_name}.ckpt' else: - print("Unrecognized model file extension for model_output_path: '{}'. Please use the '.ckpt' extension.".format( - model_output_path)) - + print(f"Unrecognized model file extension for model_output_path: '" + f"{model_output_path}'. Please use the '.ckpt' extension.") if not model_type: model_type = cfg.DEFAULT_MODEL_TYPE @@ -26,11 +26,8 @@ def train(cfg, tub_paths, model_output_path, model_type, checkpoint_path=None): tubs = tub_paths.split(',') tub_paths = [os.path.expanduser(tub) for tub in tubs] output_path = os.path.expanduser(model_output_path) - - output_dir = Path(model_output_path).parent - + output_dir = str(Path(model_output_path).parent) model = get_model_by_type(model_type, cfg, checkpoint_path=checkpoint_path) - if torch.cuda.is_available(): print('Using CUDA') gpus = -1 @@ -40,15 +37,17 @@ def train(cfg, tub_paths, model_output_path, model_type, checkpoint_path=None): logger = None if cfg.VERBOSE_TRAIN: - print("Tensorboard logging started. Run `tensorboard --logdir ./tb_logs` in a new terminal") + print("Tensorboard logging started. Run `tensorboard --logdir " + "./tb_logs` in a new terminal") from pytorch_lightning.loggers import TensorBoardLogger # Create Tensorboard logger logger = TensorBoardLogger('tb_logs', name=model_name) - weights_summary = 'full' if cfg.PRINT_MODEL_SUMMARY else 'top' - trainer = pl.Trainer(gpus=gpus, logger=logger, progress_bar_refresh_rate=30, - max_epochs=cfg.MAX_EPOCHS, default_root_dir=output_dir, weights_summary=weights_summary) + if cfg.PRINT_MODEL_SUMMARY: + summarize(model) + trainer = pl.Trainer(gpus=gpus, logger=logger, max_epochs=cfg.MAX_EPOCHS, + default_root_dir=output_dir) data_module = TorchTubDataModule(cfg, tub_paths) trainer.fit(model, data_module) diff --git a/donkeycar/tests/test_torch.py b/donkeycar/tests/test_torch.py index 63761f8d8..3d6bb9fd6 100644 --- a/donkeycar/tests/test_torch.py +++ b/donkeycar/tests/test_torch.py @@ -102,8 +102,7 @@ def test_training_pipeline(config: Config, model_type: str, car_dir: str) \ gpus = 0 # Overfit the data - trainer = pl.Trainer(gpus=gpus, overfit_batches=2, - progress_bar_refresh_rate=30, max_epochs=30) + trainer = pl.Trainer(gpus=gpus, overfit_batches=2, max_epochs=30) trainer.fit(model, data_module) final_loss = model.loss_history[-1] assert final_loss < 0.35, \ diff --git a/install/envs/mac.yml b/install/envs/mac.yml index 0e7e93e67..29f60eb74 100644 --- a/install/envs/mac.yml +++ b/install/envs/mac.yml @@ -8,6 +8,7 @@ channels: dependencies: - python=3.7 + - numpy=1.19 - h5py - pillow - opencv @@ -26,11 +27,10 @@ dependencies: - PrettyTable - pyfiglet - mypy - - pytorch=1.7.1 - - torchvision + - pytorch + - torchvision=0.12 - torchaudio - pytorch-lightning - - numpy - psutil - kivy=2.0.0 - plotly diff --git a/install/envs/ubuntu.yml b/install/envs/ubuntu.yml index 5eabe45e4..78b8c0ef2 100644 --- a/install/envs/ubuntu.yml +++ b/install/envs/ubuntu.yml @@ -8,6 +8,7 @@ channels: dependencies: - python=3.7 + - numpy=1.19 - h5py - pillow - opencv @@ -27,11 +28,10 @@ dependencies: - PrettyTable - pyfiglet - mypy - - pytorch=1.7.1 - - torchvision + - pytorch + - torchvision=0.12 - torchaudio - pytorch-lightning - - numpy - psutil - kivy=2.0.0 - plotly diff --git a/install/envs/windows.yml b/install/envs/windows.yml index 928282fc9..0b9399384 100644 --- a/install/envs/windows.yml +++ b/install/envs/windows.yml @@ -8,6 +8,7 @@ channels: dependencies: - python=3.7 + - numpy=1.19 - h5py - pillow - opencv @@ -27,11 +28,10 @@ dependencies: - PrettyTable - pyfiglet - mypy - - pytorch=1.7.1 - - torchvision + - pytorch + - torchvision=0.12 - torchaudio - pytorch-lightning - - numpy - kivy=2.0.0 - plotly - pyyaml diff --git a/setup.py b/setup.py index 5a2887484..5270bba37 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ def package_files(directory, strip_leading): long_description = fh.read() setup(name='donkeycar', - version="4.4.1-main", + version="4.4.2-main", long_description=long_description, description='Self driving library for python.', url='https://github.com/autorope/donkeycar', @@ -89,8 +89,8 @@ def package_files(directory, strip_leading): 'ci': ['codecov'], 'tf': ['tensorflow==2.2.0'], 'torch': [ - 'pytorch>=1.7.1', - 'torchvision', + 'pytorch', + 'torchvision==0.12', 'torchaudio', 'fastai' ],