Skip to content
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
44 changes: 21 additions & 23 deletions torchbenchmark/models/demucs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False


class DemucsWrapper(torch.nn.Module):
def __init__(self, model, augment):
super(DemucsWrapper, self).__init__()
self.model = model
self.augment = augment

def forward(self, streams):
sources = streams[:, 1:]
sources = self.augment(sources)
mix = sources.sum(dim=1)
return sources, self.model(mix)


class Model(BenchmarkModel):
def __init__(self, device=None, jit=False):
super().__init__()
Expand All @@ -33,7 +47,7 @@ def __init__(self, device=None, jit=False):
if 1:
samples = 80000
# TODO: calculate the right shape
self.example_inputs = (torch.rand([4, 5, 2, 135576]), )
self.example_inputs = (torch.rand([4, 5, 2, 135576], device=device),)

self.duration = Fraction(samples + args.data_stride, args.samplerate)
self.stride = Fraction(args.data_stride, args.samplerate)
Expand All @@ -49,41 +63,25 @@ def __init__(self, device=None, jit=False):
else:
self.augment = Shift(args.data_stride)

self.model = DemucsWrapper(self.model, self.augment)

def _set_mode(self, train):
self.model.train(train)

def get_module(self):
# TODO: merge this with train and eval
def helper(streams):
streams = streams.to(self.device)
sources = streams[:, 1:]
sources = self.augment(sources)
mix = sources.sum(dim=1)
return self.model(mix)
return helper, self.example_inputs
self.model.eval()
return self.model, self.example_inputs

def eval(self, niter=1):
# TODO: implement the eval version
for _ in range(niter):
streams, = self.example_inputs
streams = streams.to(self.device)
sources = streams[:, 1:]
sources = self.augment(sources)
mix = sources.sum(dim=1)

estimates = self.model(mix)
sources, estimates = self.model(*self.example_inputs)
sources = center_trim(sources, estimates)
loss = self.criterion(estimates, sources)

def train(self, niter=1):
for _ in range(niter):
streams, = self.example_inputs
streams = streams.to(self.device)
sources = streams[:, 1:]
sources = self.augment(sources)
mix = sources.sum(dim=1)

estimates = self.model(mix)
sources, estimates = self.model(*self.example_inputs)
sources = center_trim(sources, estimates)
loss = self.criterion(estimates, sources)
loss.backward()
Expand Down
2 changes: 0 additions & 2 deletions torchbenchmark/models/maml/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ def finetunning(self, x_spt, y_spt, x_qry, y_qry):
:param y_qry: [querysz]
:return:
"""
assert len(x_spt.shape) == 4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this is an unrelated change to make this module fx.symbolic_trace


querysz = x_qry.size(0)

corrects = [0 for _ in range(self.update_step_test + 1)]
Expand Down