Skip to content

#11-add pylint action #13

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

Merged
merged 2 commits into from
Aug 30, 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
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI-Pipeline

on:
pull_request:
branches: [ main ]
workflow_dispatch:

env:
PYTHON_VERSION: 3.11.5

jobs:
pylint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint

- name: Analyse code with pylint
run: |
pylint $(git ls-files '*.py') --rcfile=.pylintrc
22 changes: 22 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tool.pylint.main]
ignore-patterns = ["^\\.#"]

py-version = 3.11

[tool.pylint.basic]
no-docstring-rgx = "^_"

[tool.pylint."messages control"]
disable = raw-checker-failed, bad-inline-option, locally-disabled, file-ignored, suppressed-message, useless-suppression, deprecated-pragma, use-symbolic-message-instead, use-implicit-booleaness-not-comparison-to-string, use-implicit-booleaness-not-comparison-to-zero, missing-module-docstring, wrong-import-order, missing-function-docstring, missing-class-docstring, import-error, cyclic-import

[tool.pylint.variables]
ignored-argument-names = "_.*|^ignored_|^unused_"

[FORMAT]
max-line-length=120

[DESIGN]
max-args=10
min-public-methods=1
max-locals=20
max-attributes=20
2 changes: 1 addition & 1 deletion data/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from data.dataloader import get_mnist_loader, get_cifar10_loader
from data.dataloader import get_mnist_loader, get_cifar10_loader
11 changes: 4 additions & 7 deletions data/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ def get_mnist_loader(
val_loader = DataLoader(dataset=val_dataset, batch_size=batch_size, shuffle=shuffle, num_workers=num_workers)
return train_loader, val_loader

else:
test_dataset = MNIST(data_path, train=False, transform=transform, download=True)
return DataLoader(dataset=test_dataset, batch_size=batch_size, shuffle=shuffle, num_workers=num_workers)
test_dataset = MNIST(data_path, train=False, transform=transform, download=True)
return DataLoader(dataset=test_dataset, batch_size=batch_size, shuffle=shuffle, num_workers=num_workers)


def get_cifar10_loader(
Expand Down Expand Up @@ -64,7 +63,5 @@ def get_cifar10_loader(
val_loader = DataLoader(dataset=val_dataset, batch_size=batch_size, shuffle=shuffle, num_workers=num_workers)
return train_loader, val_loader

else:
test_dataset = CIFAR10(data_path, train=False, transform=transform, download=True)
return DataLoader(dataset=test_dataset, batch_size=batch_size, shuffle=shuffle, num_workers=num_workers
)
test_dataset = CIFAR10(data_path, train=False, transform=transform, download=True)
return DataLoader(dataset=test_dataset, batch_size=batch_size, shuffle=shuffle, num_workers=num_workers)
13 changes: 7 additions & 6 deletions model/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def forward(self, image: torch.Tensor, noise: torch.Tensor, t: int) -> torch.Ten

return image * batched_sqrt_alpha_cum_prod + noise * batched_sqrt_one_minus_alpha_cum_prod

def backward_sample(self, noise_image: torch.Tensor, noise_pred: torch.Tensor, t: int) -> Tuple[torch.Tensor, torch.Tensor]:
def backward_sample(self, noise_image: torch.Tensor, noise_pred: torch.Tensor, t: int)\
-> Tuple[torch.Tensor, torch.Tensor]:
image = (noise_image - (self.sqrt_one_minus_alpha_cum_prod[t] * noise_pred)) / self.sqrt_alpha_cum_prod[t]
image = image.clamp(-1, 1)

Expand All @@ -33,8 +34,8 @@ def backward_sample(self, noise_image: torch.Tensor, noise_pred: torch.Tensor, t

if t == 0:
return image, mean
else:
variance = ((1 - self.alpha_cum_prod[t-1]) / (1 - self.alpha_cum_prod[t])) * self.betas[t]
sigma = torch.sqrt(variance)
z = torch.randn(image.shape).to(self.device)
return image, mean + sigma * z

variance = ((1 - self.alpha_cum_prod[t - 1]) / (1 - self.alpha_cum_prod[t])) * self.betas[t]
sigma = torch.sqrt(variance)
z = torch.randn(image.shape).to(self.device)
return image, mean + sigma * z
2 changes: 1 addition & 1 deletion utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from utils.model import repeat_layers
from utils.model import repeat_layers