"vscode:/vscode.git/clone" did not exist on "9adcf60dc6d3aebb22fcf4a20ed00e1f1bdb702d"
Unverified Commit d3f71f21 authored by Rick Ho's avatar Rick Ho Committed by GitHub
Browse files

Merge pull request #113 from laekov/compat-fix

Fix smart schedule with older PyTorch
parents 5083a736 db247e85
...@@ -33,9 +33,14 @@ class MoEForward(Function): ...@@ -33,9 +33,14 @@ class MoEForward(Function):
x = x.data x = x.data
with torch.enable_grad(): with torch.enable_grad():
x.requires_grad = True x.requires_grad = True
try:
# To skip torch autograd's version check. # To skip torch autograd's version check.
with torch.autograd.graph.saved_tensors_hooks(nothing, nothing): with torch.autograd.graph.saved_tensors_hooks(nothing, nothing):
y0 = expert_fn(x, torch.tensor([x.shape[0]], dtype=torch.int64)) y0 = expert_fn(x, torch.tensor([x.shape[0]], dtype=torch.int64))
except Exception as e:
# Ignore the error and fall back for compatibility to older
# versions of PyTorch
y0 = expert_fn(x, torch.tensor([x.shape[0]], dtype=torch.int64))
ctx.gibs[idx] = x ctx.gibs[idx] = x
ctx.gobs[idx] = y0 ctx.gobs[idx] = y0
y.copy_(y0) y.copy_(y0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment