Skip to content

Commit

Permalink
feat(library): allow fallback when kernel fails
Browse files Browse the repository at this point in the history
  • Loading branch information
dacorvo committed Feb 8, 2024
1 parent 4bffe4e commit cc29588
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion quanto/library/ops.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from contextlib import contextmanager

import torch
Expand Down Expand Up @@ -41,7 +42,13 @@ def define(name, schema):
@torch.library.impl(f"quanto::{name}", "default")
def impl(*args, **kwargs):
if _ext_enabled:
return getattr(torch.ops.quanto_ext, name)(*args, **kwargs)
try:
return getattr(torch.ops.quanto_ext, name)(*args, **kwargs)
except Exception as e:
warnings.warn(
f"A {type(e)} exception occured while calling the optimized kernel for quanto::{name}."
"Falling back to default implementation."
)
return getattr(torch.ops.quanto_py, name)(*args, **kwargs)


Expand Down

0 comments on commit cc29588

Please sign in to comment.