Skip to content

Commit

Permalink
Merge branch 'Lightning-AI:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
BaruchG authored Oct 31, 2022
2 parents 030b17c + 78cbcdd commit 6e6a878
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 25 deletions.
8 changes: 5 additions & 3 deletions .azure/gpu-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
container:
image: "pytorchlightning/pytorch_lightning:base-cuda-py3.9-torch1.12-cuda11.6.1"
#endpoint: azureContainerRegistryConnection
options: "--gpus=all --shm-size=16g --name ci-container -v /usr/bin/docker:/tmp/docker:ro"
options: "--gpus=all --shm-size=16g -v /usr/bin/docker:/tmp/docker:ro"

workspace:
clean: all
Expand All @@ -34,12 +34,14 @@ jobs:

- bash: |
echo "##vso[task.setvariable variable=CUDA_VISIBLE_DEVICES]$(DEVICES)"
displayName: 'set visible devices'
echo "##vso[task.setvariable variable=CONTAINER_ID]$(head -1 /proc/self/cgroup|cut -d/ -f3)"
displayName: 'Set environment variables'
- bash: |
whereis nvidia
nvidia-smi
echo $CUDA_VISIBLE_DEVICES
echo $CONTAINER_ID
python --version
pip --version
pip list
Expand All @@ -50,7 +52,7 @@ jobs:
displayName: 'Sanity check'
- script: |
/tmp/docker exec -t -u 0 ci-container \
/tmp/docker exec -t -u 0 $CONTAINER_ID \
sh -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" -y install sudo"
displayName: 'Install Sudo in container (thanks Microsoft!)'
Expand Down
7 changes: 2 additions & 5 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,9 @@ jobs:
--ignore=pl_bolts/models/self_supervised/amdim/transforms.py \
--ignore=pl_bolts/models/rl
# Note: This uses an internal pip API and may not always work
# https://github.com/actions/cache/blob/master/examples.md#multiple-oss-in-a-workflow
- name: Get pip cache
- name: Get pip cache dir
id: pip-cache
run: |
python -c "from pip._internal.locations import USER_CACHE_DIR; print('::set-output name=dir::' + USER_CACHE_DIR)"
run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT

- name: Cache pip
uses: actions/cache@v3
Expand Down
7 changes: 2 additions & 5 deletions pl_bolts/models/gans/dcgan/components.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Based on https://github.com/pytorch/examples/blob/master/dcgan/main.py
from torch import Tensor, nn
import torch.nn as nn
from torch import Tensor

from pl_bolts.utils.stability import under_review


@under_review()
class DCGANGenerator(nn.Module):
def __init__(self, latent_dim: int, feature_maps: int, image_channels: int) -> None:
"""
Expand Down Expand Up @@ -50,7 +48,6 @@ def forward(self, noise: Tensor) -> Tensor:
return self.gen(noise)


@under_review()
class DCGANDiscriminator(nn.Module):
def __init__(self, feature_maps: int, image_channels: int) -> None:
"""
Expand Down
14 changes: 6 additions & 8 deletions pl_bolts/models/gans/dcgan/dcgan_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from typing import Any

import torch
import torch.nn as nn
from pytorch_lightning import LightningModule, Trainer, seed_everything
from torch import Tensor, nn
from torch import Tensor
from torch.utils.data import DataLoader

from pl_bolts.callbacks import LatentDimInterpolator, TensorboardGenerativeModelImageSampler
from pl_bolts.models.gans.dcgan.components import DCGANDiscriminator, DCGANGenerator
from pl_bolts.utils import _TORCHVISION_AVAILABLE
from pl_bolts.utils.stability import under_review
from pl_bolts.utils.warnings import warn_missing_pkg

if _TORCHVISION_AVAILABLE:
Expand All @@ -19,7 +19,6 @@
warn_missing_pkg("torchvision")


@under_review()
class DCGAN(LightningModule):
"""DCGAN implementation.
Expand All @@ -28,7 +27,7 @@ class DCGAN(LightningModule):
from pl_bolts.models.gans import DCGAN
m = DCGAN()
Trainer(gpus=2).fit(m)
Trainer(accelerator="gpu", devices=2).fit(m)
Example CLI::
Expand Down Expand Up @@ -80,10 +79,10 @@ def _get_discriminator(self) -> nn.Module:
def _weights_init(m):
classname = m.__class__.__name__
if classname.find("Conv") != -1:
torch.nn.init.normal_(m.weight, 0.0, 0.02)
nn.init.normal_(m.weight, 0.0, 0.02)
elif classname.find("BatchNorm") != -1:
torch.nn.init.normal_(m.weight, 1.0, 0.02)
torch.nn.init.zeros_(m.bias)
nn.init.normal_(m.weight, 1.0, 0.02)
nn.init.zeros_(m.bias)

def configure_optimizers(self):
lr = self.hparams.learning_rate
Expand Down Expand Up @@ -173,7 +172,6 @@ def add_model_specific_args(parent_parser: ArgumentParser) -> ArgumentParser:
return parser


@under_review()
def cli_main(args=None):
seed_everything(1234)

Expand Down
2 changes: 2 additions & 0 deletions pl_bolts/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
_TORCH_ORT_AVAILABLE = module_available("torch_ort")
_TORCH_MAX_VERSION_SPARSEML = compare_version("torch", operator.lt, "1.11.0")
_SPARSEML_AVAILABLE = module_available("sparseml") and _PL_GREATER_EQUAL_1_4_5 and _TORCH_MAX_VERSION_SPARSEML
_JSONARGPARSE_GREATER_THAN_4_16_0 = compare_version("jsonargparse", operator.gt, "4.16.0")


__all__ = ["BatchGradientVerification"]
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
torch>=1.9.*
torchmetrics>=0.4.1
pytorch-lightning>=1.6.0
lightning-utilities==0.3.0
lightning-utilities==0.4.*, !=0.4.0
packaging
8 changes: 5 additions & 3 deletions tests/models/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from pl_bolts.utils import _JSONARGPARSE_GREATER_THAN_4_16_0
from tests import _MARK_REQUIRE_GPU, DATASETS_PATH

_DEFAULT_ARGS = f" --data_dir {DATASETS_PATH} --max_epochs 1 --max_steps 2 --batch_size 4"
Expand All @@ -13,9 +14,7 @@
@pytest.mark.parametrize("dataset_name", ["mnist", "cifar10"])
@pytest.mark.parametrize(
"cli_args",
[
" --dataset %(dataset_name)s" + _DEFAULT_ARGS,
],
[" --dataset %(dataset_name)s" + _DEFAULT_ARGS],
)
def test_cli_run_basic_gan(cli_args, dataset_name):
from pl_bolts.models.gans.basic.basic_gan_module import cli_main
Expand Down Expand Up @@ -112,6 +111,9 @@ def test_cli_run_vision_image_gpt(cli_args):

@pytest.mark.parametrize("cli_args", [_DEFAULT_LIGHTNING_CLI_ARGS + " --trainer.gpus 1"])
@pytest.mark.skipif(**_MARK_REQUIRE_GPU)
@pytest.mark.skipif(
not _JSONARGPARSE_GREATER_THAN_4_16_0, reason="Failing on CI, need to be fixed"
) # see https://github.com/omni-us/jsonargparse/issues/187
def test_cli_run_retinanet(cli_args):
"""Test running CLI for an example with default params."""
from pl_bolts.models.detection.retinanet.retinanet_module import cli_main
Expand Down

0 comments on commit 6e6a878

Please sign in to comment.