Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda committed Jul 4, 2023
2 parents a5f33e7 + 899f40d commit 8ae8eba
Show file tree
Hide file tree
Showing 24 changed files with 43 additions and 89 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ on:

jobs:
check-schema:
uses: Lightning-AI/utilities/.github/workflows/check-schema.yml@v0.8.0
uses: Lightning-AI/utilities/.github/workflows/check-schema.yml@v0.9.0
with:
azure-dir: ".azure"

check-code:
uses: Lightning-AI/utilities/.github/workflows/check-code.yml@v0.8.0
uses: Lightning-AI/utilities/.github/workflows/check-code.yml@v0.9.0
with:
actions-ref: v0.8.0
extra-typing: typing

check-package:
uses: Lightning-AI/utilities/.github/workflows/check-package.yml@v0.8.0
uses: Lightning-AI/utilities/.github/workflows/check-package.yml@v0.9.0
with:
actions-ref: v0.8.0
artifact-name: dist-packages-${{ github.sha }}
Expand Down
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ repos:
- id: detect-private-key

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

- repo: https://github.com/PyCQA/docformatter
rev: v1.7.1
rev: v1.7.3
hooks:
- id: docformatter
args: [--in-place, --wrap-summaries=115, --wrap-descriptions=120]
Expand All @@ -56,16 +56,16 @@ repos:
name: Format code

- repo: https://github.com/asottile/yesqa
rev: v1.4.0
rev: v1.5.0
hooks:
- id: yesqa
additional_dependencies:
- flake8-pytest-style
- flake8-bandit
- pep8-naming

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.272
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.276
hooks:
- id: ruff
args: ["--fix"]
2 changes: 1 addition & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pytest-cov ==4.1.0
pytest-timeout ==2.1.0
pytest-rerunfailures ==11.1.2

scikit-learn >=1.0.2, <=1.2.2
scikit-learn >=1.0.2, <=1.3.0
sparseml >1.0.0, <1.6.0
ale-py >=0.7, <=0.8.1
jsonargparse[signatures] >4.0.0, <=4.22.0 # for LightningCLI
2 changes: 1 addition & 1 deletion requirements/typing.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mypy ==1.3.0
mypy ==1.4.1
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,12 @@ def _load_readme_description(path_dir: str, homepage: str, ver: str) -> str:
skip_begin = r"<!-- following section will be skipped from PyPI description -->"
skip_end = r"<!-- end skipping PyPI description -->"
# todo: wrap content as commented description
text = re.sub(rf"{skip_begin}.+?{skip_end}", "<!-- -->", text, flags=re.IGNORECASE + re.DOTALL)
return re.sub(rf"{skip_begin}.+?{skip_end}", "<!-- -->", text, flags=re.IGNORECASE + re.DOTALL)

# # https://github.com/Borda/pytorch-lightning/releases/download/1.1.0a6/codecov_badge.png
# github_release_url = os.path.join(homepage, "releases", "download", ver)
# # download badge and replace url with local file
# text = _parse_for_badge(text, github_release_url)
return text


def _prepare_extras():
Expand Down
6 changes: 2 additions & 4 deletions src/pl_bolts/losses/self_supervised_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ def forward(self, z):
if not torch.isnan(loss):
losses.append(loss)

loss = torch.stack(losses).sum()
return loss
return torch.stack(losses).sum()


@under_review()
Expand Down Expand Up @@ -255,8 +254,7 @@ def feat_size_w_mask(self, w, feature_map):
for i in range(w):
for j in range(w):
masks_r5[i, j, 0, i, j] = 1
masks_r5 = masks_r5.reshape(-1, 1, w, w)
return masks_r5
return masks_r5.reshape(-1, 1, w, w)

def _sample_src_ftr(self, r_cnv, masks):
# get feature dimensions
Expand Down
20 changes: 6 additions & 14 deletions src/pl_bolts/models/autoencoders/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ def forward(self, x):
identity = self.downsample(x)

out += identity
out = self.relu(out)

return out
return self.relu(out)


@under_review()
Expand Down Expand Up @@ -117,8 +115,7 @@ def forward(self, x):
identity = self.downsample(x)

out += identity
out = self.relu(out)
return out
return self.relu(out)


@under_review()
Expand Down Expand Up @@ -150,9 +147,7 @@ def forward(self, x):
identity = self.upsample(x)

out += identity
out = self.relu(out)

return out
return self.relu(out)


@under_review()
Expand Down Expand Up @@ -192,8 +187,7 @@ def forward(self, x):
identity = self.upsample(x)

out += identity
out = self.relu(out)
return out
return self.relu(out)


@under_review()
Expand Down Expand Up @@ -252,8 +246,7 @@ def forward(self, x):
x = self.layer4(x)

x = self.avgpool(x)
x = torch.flatten(x, 1)
return x
return torch.flatten(x, 1)


@under_review()
Expand Down Expand Up @@ -325,8 +318,7 @@ def forward(self, x):
x = self.layer4(x)
x = self.upscale(x)

x = self.conv1(x)
return x
return self.conv1(x)


@under_review()
Expand Down
3 changes: 1 addition & 2 deletions src/pl_bolts/models/detection/yolo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ def box_size_ratio(wh1: Tensor, wh2: Tensor) -> Tensor:
"""
wh_ratio = wh1[:, None, :] / wh2[None, :, :] # [M, N, 2]
wh_ratio = torch.max(wh_ratio, 1.0 / wh_ratio)
wh_ratio = wh_ratio.max(2).values # [M, N]
return wh_ratio
return wh_ratio.max(2).values # [M, N]


@torch.jit.script
Expand Down
3 changes: 1 addition & 2 deletions src/pl_bolts/models/detection/yolo/yolo_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ class labels.
"""
images, _ = batch
detections = self(images)
detections = self.process_detections(detections)
return detections
return self.process_detections(detections)

def infer(self, image: Tensor) -> PRED:
"""Feeds an image to the network and returns the detected bounding boxes, confidence scores, and class
Expand Down
3 changes: 1 addition & 2 deletions src/pl_bolts/models/gans/basic/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def forward(self, z):
z = F.leaky_relu(self.fc2(z), 0.2)
z = F.leaky_relu(self.fc3(z), 0.2)
img = torch.tanh(self.fc4(z))
img = img.view(img.size(0), *self.img_shape)
return img
return img.view(img.size(0), *self.img_shape)


class Discriminator(nn.Module):
Expand Down
6 changes: 2 additions & 4 deletions src/pl_bolts/models/gans/srgan/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
x_res = self.input_block(x)
x = x_res + self.res_blocks(x_res)
x = self.ps_blocks(x)
x = self.output_block(x)
return x
return self.output_block(x)


@under_review()
Expand Down Expand Up @@ -131,8 +130,7 @@ def _make_conv_block(

def forward(self, x: torch.Tensor) -> torch.Tensor:
x = self.conv_blocks(x)
x = self.mlp(x)
return x
return self.mlp(x)


@under_review()
Expand Down
3 changes: 1 addition & 2 deletions src/pl_bolts/models/mnist_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def __init__(self, hidden_dim: int = 128, learning_rate: float = 1e-3, **kwargs:
def forward(self, x: Tensor) -> Tensor:
out = x.view(x.size(0), -1)
out = torch.relu(self.l1(out))
out = torch.relu(self.l2(out))
return out
return torch.relu(self.l2(out))

def shared_step(self, batch: Any, batch_idx: int, step: str) -> Tensor:
x, y = batch
Expand Down
4 changes: 1 addition & 3 deletions src/pl_bolts/models/rl/advantage_actor_critic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ def compute_returns(
returns.append(g)

# reverse list and stop the gradients
returns = torch.tensor(returns[::-1])

return returns
return torch.tensor(returns[::-1])

def loss(
self,
Expand Down
4 changes: 1 addition & 3 deletions src/pl_bolts/models/rl/vanilla_policy_gradient_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ def compute_returns(self, rewards):
returns.insert(0, reward)

returns = torch.tensor(returns)
returns = (returns - returns.mean()) / (returns.std() + self.eps)

return returns
return (returns - returns.mean()) / (returns.std() + self.eps)

def loss(self, states, actions, scaled_rewards) -> Tensor:
"""Calculates the loss for VPG.
Expand Down
11 changes: 3 additions & 8 deletions src/pl_bolts/models/self_supervised/cpc/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ def _make_layer(self, sample_batch, block, planes, blocks, stride=1, dilate=Fals

def flatten(self, x):
x = x.view(self.batch_size, -1)
x = F.avg_pool1d(x.unsqueeze(1), 4).squeeze(1)
return x
return F.avg_pool1d(x.unsqueeze(1), 4).squeeze(1)

def forward(self, x):
x = self.conv1(x)
Expand All @@ -126,9 +125,7 @@ def forward(self, x):
x = self.layer1(x)
x = self.layer2(x)
x = self.layer3(x)
x = self.layer4(x)

return x
return self.layer4(x)


@under_review()
Expand Down Expand Up @@ -202,9 +199,7 @@ def forward(self, x):
identity = self.downsample(x)

out += identity
out = self.relu(out)

return out
return self.relu(out)


@under_review()
Expand Down
8 changes: 2 additions & 6 deletions src/pl_bolts/models/self_supervised/resnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ def forward(self, x):
identity = self.downsample(x)

out += identity
out = self.relu(out)

return out
return self.relu(out)


@under_review()
Expand Down Expand Up @@ -133,9 +131,7 @@ def forward(self, x):
identity = self.downsample(x)

out += identity
out = self.relu(out)

return out
return self.relu(out)


@under_review()
Expand Down
4 changes: 1 addition & 3 deletions src/pl_bolts/models/self_supervised/simclr/simclr_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def forward(ctx, tensor):
gathered_tensor = [torch.zeros_like(tensor) for _ in range(torch.distributed.get_world_size())]

torch.distributed.all_gather(gathered_tensor, tensor)
gathered_tensor = torch.cat(gathered_tensor, 0)

return gathered_tensor
return torch.cat(gathered_tensor, 0)

@staticmethod
def backward(ctx, grad_output):
Expand Down
12 changes: 3 additions & 9 deletions src/pl_bolts/models/self_supervised/swav/swav_resnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def forward(self, x):
identity = self.downsample(x)

out += identity
out = self.relu(out)

return out
return self.relu(out)


class Bottleneck(nn.Module):
Expand Down Expand Up @@ -120,9 +118,7 @@ def forward(self, x):
identity = self.downsample(x)

out += identity
out = self.relu(out)

return out
return self.relu(out)


class ResNet(nn.Module):
Expand Down Expand Up @@ -294,9 +290,7 @@ def forward_backbone(self, x):
return x

x = self.avgpool(x)
x = torch.flatten(x, 1)

return x
return torch.flatten(x, 1)

def forward_head(self, x):
if self.projection_head is not None:
Expand Down
3 changes: 1 addition & 2 deletions src/pl_bolts/models/vision/image_gpt/gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ def forward(self, x):
a, _ = self.attn(x, x, x, attn_mask=attn_mask, need_weights=False)
x = x + a
m = self.mlp(self.ln_2(x))
x = x + m
return x
return x + m


@under_review()
Expand Down
3 changes: 1 addition & 2 deletions src/pl_bolts/models/vision/image_gpt/igpt_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
def _shape_input(x):
"""Shape batch of images for input into GPT2 model."""
x = x.view(x.shape[0], -1) # flatten images into sequences
x = x.transpose(0, 1).contiguous() # to shape [seq len, batch]
return x
return x.transpose(0, 1).contiguous() # to shape [seq len, batch]


@under_review()
Expand Down
3 changes: 1 addition & 2 deletions src/pl_bolts/models/vision/pixel_cnn.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""PixelCNN.
Implemented by: William Falcon Reference
: https: //arxiv.org/pdf/1905.09272.pdf (page 15
Accessed: May 14, 2020.
: https: //arxiv.org/pdf/1905.09272.pdf (page 15 Accessed: May 14, 2020.
"""
from torch import nn
from torch.nn import functional as F # noqa: N812
Expand Down
3 changes: 1 addition & 2 deletions src/pl_bolts/transforms/self_supervised/moco_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,4 @@ def __init__(self, sigma: List[float] = [0.1, 2.0]) -> None:

def __call__(self, x):
sigma = random.uniform(self.sigma[0], self.sigma[1]) # noqa: S311
x = x.filter(ImageFilter.GaussianBlur(radius=sigma))
return x
return x.filter(ImageFilter.GaussianBlur(radius=sigma))
Loading

0 comments on commit 8ae8eba

Please sign in to comment.