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

Moved ParamScheduler tests to core #2136

Merged
merged 2 commits into from
Aug 4, 2021
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
32 changes: 32 additions & 0 deletions tests/ignite/handlers/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import pytest
import torch


@pytest.fixture()
def dummy_model_factory():
class DummyModel(torch.nn.Module):
def __init__(self):
super(DummyModel, self).__init__()
self.fc1 = torch.nn.Linear(10, 10)
self.fc2 = torch.nn.Linear(12, 12)
self.fc1.weight.data.zero_()
self.fc1.bias.data.zero_()
self.fc2.weight.data.fill_(1.0)
self.fc2.bias.data.fill_(1.0)

def get_dummy_model(with_grads=True, with_frozen_layer=False):
model = DummyModel()
if with_grads:
model.fc2.weight.grad = torch.zeros_like(model.fc2.weight)
model.fc2.bias.grad = torch.zeros_like(model.fc2.bias)

if not with_frozen_layer:
model.fc1.weight.grad = torch.zeros_like(model.fc1.weight)
model.fc1.bias.grad = torch.zeros_like(model.fc1.bias)

if with_frozen_layer:
for param in model.fc1.parameters():
param.requires_grad = False
return model

return get_dummy_model