Skip to content

Instantly share code, notes, and snippets.

@liangfu
Created December 2, 2024 23:12
Show Gist options
  • Save liangfu/67fd1cbd0c2ebd5ce9a91648ffc9c246 to your computer and use it in GitHub Desktop.
Save liangfu/67fd1cbd0c2ebd5ce9a91648ffc9c246 to your computer and use it in GitHub Desktop.
Demonstrate the feasibility of combining depyf with openxla backend
import torch
import torch_xla.core.xla_model as xm
@torch.compile(backend="openxla")
def toy_example(a, b):
x = a / (torch.abs(a) + 1)
if b.sum() < 0:
b = b * -1
return x * b
def main():
device = xm.xla_device()
a = torch.randn(10).to(device=device)*10
b = torch.randn(10).to(device=device)*10
for _ in range(4):
print(toy_example(a, b).to(device="cpu"))
if __name__ == "__main__":
import depyf
with depyf.prepare_debug("depyf_debug_dir"):
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment