Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump ruff from 0.1.14 to 0.4.10 #357

Merged
merged 9 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions .github/collect_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,13 @@ def get_nvidia_smi():
def get_platform():
if sys.platform.startswith("linux"):
return "linux"
elif sys.platform.startswith("win32"):
if sys.platform.startswith("win32"):
return "win32"
elif sys.platform.startswith("cygwin"):
if sys.platform.startswith("cygwin"):
return "cygwin"
elif sys.platform.startswith("darwin"):
if sys.platform.startswith("darwin"):
return "darwin"
else:
return sys.platform
return sys.platform


def get_mac_version(run_lambda):
Expand Down
8 changes: 7 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,10 @@

'topic: build':
- changed-files:
- any-glob-to-any-file: setup.py
- any-glob-to-any-file:
- setup.py
- pyproject.toml

'topic: style':
- changed-files:
- any-glob-to-any-file: .pre-commit-config.yaml
4 changes: 1 addition & 3 deletions .github/verify_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def parse_args():
)

parser.add_argument("pr", type=int, help="PR number")
args = parser.parse_args()

return args
return parser.parse_args()


if __name__ == "__main__":
Expand Down
15 changes: 8 additions & 7 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ jobs:
architecture: x64
- name: Run ruff
run: |
pip install ruff==0.1.14
python -m pip install --upgrade uv
uv pip install --system -e '.[quality]'
ruff --version
ruff check --diff .

Expand All @@ -44,10 +45,8 @@ jobs:
key: ${{ runner.os }}-python-${{ matrix.python }}-${{ hashFiles('pyproject.toml') }}-quality
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e '.[quality]'
- name: Run mypy
run: |
python -m pip install --upgrade uv
uv pip install --system -e '.[quality]'
mypy --version
mypy

Expand All @@ -65,7 +64,8 @@ jobs:
architecture: x64
- name: Run ruff
run: |
pip install ruff==0.1.14
python -m pip install --upgrade uv
uv pip install --system -e '.[quality]'
ruff --version
ruff format --check --diff .

Expand All @@ -83,7 +83,8 @@ jobs:
architecture: x64
- name: Run ruff
run: |
pip install pre-commit
python -m pip install --upgrade uv
uv pip install --system -e '.[quality]'
git checkout -b temp
pre-commit install
pre-commit --version
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
args: ['--branch', 'main']
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.1.14'
rev: 'v0.4.10'
hooks:
- id: ruff
args:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ quality:
# this target runs checks on all files and potentially modifies some of them
style:
ruff format .
ruff --fix .
ruff check --fix .

# Run tests for the library
test:
Expand Down
2 changes: 1 addition & 1 deletion api/app/routes/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@router.post("/", status_code=status.HTTP_200_OK, summary="Perform image classification")
async def classify(file: UploadFile = File(...)) -> ClsCandidate:
def classify(file: UploadFile = File(...)) -> ClsCandidate:
"""Runs holocron vision model to analyze the input image"""
probs = classify_image(decode_image(file.file.read()))

Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def inject_checkpoint_metadata(app, what, name, obj, options, lines):
table.extend((
("url", f"`link <{meta.url}>`__"),
("sha256", meta.sha256[:16]),
("size", f"{meta.size / 1024 ** 2:.1f}MB"),
("size", f"{meta.size / 1024**2:.1f}MB"),
("num_params", f"{meta.num_params / 1000000.0:.1f}M"),
))
# Wrap the text
Expand Down
4 changes: 1 addition & 3 deletions holocron/models/classification/sknet.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
b, m, c = paths.shape[:3]
z = self.sa(paths.sum(dim=1)).view(b, m, c, 1, 1)
attention_factors = torch.softmax(z, dim=1)
out = (attention_factors * paths).sum(dim=1)

return out
return (attention_factors * paths).sum(dim=1)


class SKBottleneck(_ResBlock):
Expand Down
4 changes: 1 addition & 3 deletions holocron/models/classification/tridentnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
dilations = [1] * self.num_branches if self.dilation[0] == 1 else [1 + idx for idx in range(self.num_branches)]

# Use shared weight to apply the convolution
out = torch.cat(
return torch.cat(
[
F.conv2d(
_x,
Expand All @@ -57,8 +57,6 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:
1,
)

return out


class Tridentneck(_ResBlock):
expansion: int = 4
Expand Down
4 changes: 1 addition & 3 deletions holocron/models/detection/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,7 @@ def _format_outputs(self, x: Tensor) -> Tuple[Tensor, Tensor, Tensor]:
def _forward(self, x: Tensor) -> Tensor:
out = self.backbone(x)
out = self.block4(out)
out = self.classifier(out)

return out
return self.classifier(out)

def forward(
self, x: Tensor, target: Optional[List[Dict[str, Tensor]]] = None
Expand Down
4 changes: 1 addition & 3 deletions holocron/models/detection/yolov2.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ def _forward(self, x: Tensor) -> Tensor:
out = torch.cat((passthrough, out), 1)
out = self.block6(out)

out = self.head(out)

return out
return self.head(out)

def forward(
self, x: Union[Tensor, List[Tensor], Tuple[Tensor, ...]], target: Optional[List[Dict[str, Tensor]]] = None
Expand Down
3 changes: 1 addition & 2 deletions holocron/models/detection/yolov4.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,15 +628,14 @@ def forward(
y3 = self.yolo3(o3, target)

if not self.training:
detections = [
return [
{
"boxes": torch.cat((det1["boxes"], det2["boxes"], det3["boxes"]), dim=0),
"scores": torch.cat((det1["scores"], det2["scores"], det3["scores"]), dim=0),
"labels": torch.cat((det1["labels"], det2["labels"], det3["labels"]), dim=0),
}
for det1, det2, det3 in zip(y1, y2, y3)
]
return detections

return {k: y1[k] + y2[k] + y3[k] for k in y1}

Expand Down
6 changes: 2 additions & 4 deletions holocron/models/segmentation/unet.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ def forward(self, x: Tensor) -> Tensor:
x = decoder(xs.pop(), x)

# Classifier
x = self.classifier(x)
return x
return self.classifier(x)


class UBlock(nn.Module):
Expand Down Expand Up @@ -368,8 +367,7 @@ def forward(self, x: Tensor) -> Tensor:
x = self.upsample(x)

# Classifier
x = self.classifier(x)
return x
return self.classifier(x)


def _unet(arch: str, pretrained: bool, progress: bool, **kwargs: Any) -> UNet:
Expand Down
3 changes: 1 addition & 2 deletions holocron/models/segmentation/unet3p.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ def forward(self, x: Tensor) -> Tensor:
xs[idx] = self.decoder[idx](xs[:idx], xs[idx], xs[idx + 1 :])

# Classifier
x = self.classifier(xs[0])
return x
return self.classifier(xs[0])


def _unet(arch: str, pretrained: bool, progress: bool, **kwargs: Any) -> nn.Module:
Expand Down
8 changes: 2 additions & 6 deletions holocron/nn/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ def concat_downsample2d(x: Tensor, scale_factor: int) -> Tensor:
# N * C * H * W --> N * C * (H/scale_factor) * scale_factor * (W/scale_factor) * scale_factor
x = x.view(b, c, h // scale_factor, scale_factor, w // scale_factor, scale_factor)
x = x.permute(0, 3, 5, 1, 2, 4).contiguous()
x = x.view(b, int(c * scale_factor**2), h // scale_factor, w // scale_factor)

return x
return x.view(b, int(c * scale_factor**2), h // scale_factor, w // scale_factor)


def z_pool(x: Tensor, dim: int) -> Tensor:
Expand Down Expand Up @@ -364,9 +362,7 @@ def _xcorr2d(
h = floor((h + (2 * padding[0]) - (dilation[0] * (weight.shape[-2] - 1)) - 1) / stride[0] + 1)
w = floor((w + (2 * padding[1]) - (dilation[1] * (weight.shape[-1] - 1)) - 1) / stride[1] + 1)

x = x.view(-1, weight.shape[0], h, w)

return x
return x.view(-1, weight.shape[0], h, w)


def _convNd(x: Tensor, weight: Tensor) -> Tensor:
Expand Down
6 changes: 2 additions & 4 deletions holocron/nn/modules/activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ def __init__(self, inplace: bool = False) -> None:
self.inplace = inplace

def extra_repr(self) -> str:
inplace_str = "inplace=True" if self.inplace else ""
return inplace_str
return "inplace=True" if self.inplace else ""


class HardMish(_Activation):
Expand Down Expand Up @@ -80,5 +79,4 @@ def __init__(self, in_channels: int, kernel_size: int = 3) -> None:
def forward(self, x: Tensor) -> Tensor:
out = self.conv(x)
out = self.bn(out)
x = torch.max(x, out)
return x
return torch.max(x, out)
3 changes: 1 addition & 2 deletions holocron/nn/modules/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ def forward(self, x: Tensor) -> Tensor:
x_h = cast(Tensor, self.h_branch(x))
x_w = cast(Tensor, self.w_branch(x))

out = (x_c + x_h + x_w) / 3
return out
return (x_c + x_h + x_w) / 3
4 changes: 1 addition & 3 deletions holocron/nn/modules/conv.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,4 @@ def forward(self, x: Tensor) -> Tensor:

# Multiply-Add operation
# --> (N, C, H // s, W // s)
out = (kernel * x_unfolded).sum(dim=3).view(*x.shape[:2], *kernel.shape[-2:])

return out
return (kernel * x_unfolded).sum(dim=3).view(*x.shape[:2], *kernel.shape[-2:])
9 changes: 3 additions & 6 deletions holocron/nn/modules/downsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def forward(self, x: Tensor) -> Tensor:
return x.view(x.size(0), x.size(1), -1).mean(-1).view(x.size(0), x.size(1), 1, 1)

def extra_repr(self) -> str:
inplace_str = "flatten=True" if self.flatten else ""
return inplace_str
return "flatten=True" if self.flatten else ""


class GlobalMaxPool2d(nn.Module):
Expand All @@ -97,13 +96,11 @@ def forward(self, x: Tensor) -> Tensor:
return x.view(x.size(0), x.size(1), -1).max(-1).values.view(x.size(0), x.size(1), 1, 1)

def extra_repr(self) -> str:
inplace_str = "flatten=True" if self.flatten else ""
return inplace_str
return "flatten=True" if self.flatten else ""


def get_padding(kernel_size: int, stride: int = 1, dilation: int = 1) -> int:
padding = ((stride - 1) + dilation * (kernel_size - 1)) // 2
return padding
return ((stride - 1) + dilation * (kernel_size - 1)) // 2


class BlurPool2d(nn.Module):
Expand Down
3 changes: 1 addition & 2 deletions holocron/nn/modules/lambda_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,4 @@ def forward(self, x: torch.Tensor) -> torch.Tensor:

Y = Yc + Yp
# B x (H * W) x num_heads x dim_v -> B x (num_heads * dim_v) x H x W
out = Y.permute(0, 2, 3, 1).reshape(b, self.num_heads * v.shape[2], h, w)
return out
return Y.permute(0, 2, 3, 1).reshape(b, self.num_heads * v.shape[2], h, w)
3 changes: 1 addition & 2 deletions holocron/trainer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ def find_lr(
if torch.isnan(batch_loss) or torch.isinf(batch_loss):
if batch_idx == 0:
raise ValueError("loss value is NaN or inf.")
else:
break
break
self.loss_recorder.append(batch_loss.item())
# Stop after the number of iterations
if batch_idx + 1 == num_it:
Expand Down
15 changes: 7 additions & 8 deletions holocron/transforms/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,13 @@ def get_params(self, image: Union[Image.Image, torch.Tensor]) -> Tuple[int, int]
def forward(self, image: Union[Image.Image, torch.Tensor]) -> Union[Image.Image, torch.Tensor]:
if self.mode == ResizeMethod.SQUISH:
return super().forward(image)
else:
h, w = self.get_params(image)
img = resize(image, (h, w), self.interpolation)
# get the padding
h_pad, w_pad = self.size[0] - h, self.size[1] - w
_padding = w_pad // 2, h_pad // 2, w_pad - w_pad // 2, h_pad - h_pad // 2
# Fill the rest up to target_size
return pad(img, _padding, padding_mode=self.pad_mode)
h, w = self.get_params(image)
img = resize(image, (h, w), self.interpolation)
# get the padding
h_pad, w_pad = self.size[0] - h, self.size[1] - w
_padding = w_pad // 2, h_pad // 2, w_pad - w_pad // 2, h_pad - h_pad // 2
# Fill the rest up to target_size
return pad(img, _padding, padding_mode=self.pad_mode)


class RandomZoomOut(nn.Module):
Expand Down
Loading
Loading