{"id":22471,"library":"torch-xla","title":"PyTorch/XLA","description":"PyTorch/XLA is a Python package that bridges PyTorch with XLA devices (TPU, GPU, CPU) to enable high-performance machine learning. The current stable version is 2.9.0, with releases aligned to PyTorch minor versions. It supports Python 3.10-3.13 and provides both PJRT and XRT runtimes (PJRT recommended).","status":"active","version":"2.9.0","language":"python","source_language":"en","source_url":"https://github.com/pytorch/xla","tags":["pytorch","xla","tpu","google","machine-learning","deep-learning"],"install":[{"cmd":"pip install torch torch_xla[tpu] -f https://storage.googleapis.com/libtpu-releases/index.html","lang":"bash","label":"Install with TPU support"}],"dependencies":[{"reason":"PyTorch/XLA is an XLA bridge for PyTorch","package":"torch","optional":false},{"reason":"Experimental JAX interoperability","package":"jax","optional":true}],"imports":[{"note":"torch_xla is a package; importing directly works. 'from torch_xla import xla_model' is outdated and may miss other submodules.","wrong":"from torch_xla import xla_model","symbol":"torch_xla","correct":"import torch_xla"},{"note":"The correct module path is 'torch_xla.core.xla_model', not a top-level xla_model.","wrong":"import torch_xla.xla_model as xm","symbol":"torch_xla.core.xla_model","correct":"import torch_xla.core.xla_model as xm"}],"quickstart":{"code":"import torch\nimport torch_xla\nimport torch_xla.core.xla_model as xm\n\n# Get XLA device\ndevice = xm.xla_device()\n\n# Create tensor on XLA device\nt = torch.randn(3, 3, device=device)\nprint(f\"Tensor device: {t.device}\")\n\n# Perform operations\nresult = t + t\nprint(f\"Result: {result}\")\n\n# Mark step and synchronize (required for XLA)\nxm.mark_step()\nxm.wait_device_ops()","lang":"python","description":"Basic example: get XLA device, create tensor, run ops, mark step."},"warnings":[{"fix":"Ensure you are using PJRT (default). If you explicitly used XRT, switch to PJRT by not setting XRT runtime env vars.","message":"XRT runtime is deprecated and removed in PyTorch/XLA 2.1+. Use PJRT runtime for all new code.","severity":"breaking","affected_versions":">=2.1.0"},{"fix":"Call xm.mark_step() after each training step and xm.wait_device_ops() before measuring time or synchronizing.","message":"Missing call to xm.mark_step() or xm.wait_device_ops() causes lazy execution to not materialize, leading to hangs or incorrect results.","severity":"gotcha","affected_versions":"all"},{"fix":"Install libtpu directly: pip install torch_xla[tpu] -f https://storage.googleapis.com/libtpu-releases/index.html for PyTorch/XLA 2.9+ it installs libtpu automatically.","message":"Library installation extra [tpu] installs torch-xla but may conflict with newer versions of libtpu. Use separate pip install with index URL.","severity":"deprecated","affected_versions":"<2.9.0"}],"env_vars":null,"search_vec":"'-3.13':40 '2.9.0':28 '3.10':39 'align':31 'bridg':8 'cpu':15 'current':24 'deep':58 'deep-learn':57 'devic':12 'enabl':17 'googl':53 'gpu':14 'high':19 'high-perform':18 'learn':22,56,59 'machin':21,55 'machine-learn':54 'minor':34 'packag':6 'perform':20 'pjrt':44,48 'provid':42 'python':5,38 'pytorch':9,33,50 'pytorch/xla':1,2 'recommend':49 'releas':30 'runtim':47 'stabl':25 'support':37 'tpu':13,52 'version':26,35 'xla':11,51 'xrt':46","created_at":"2026-04-27T17:05:21.412082+00:00","updated_at":"2026-04-27T17:05:21.412082+00:00","problems":{"verify_error":"error: Failed to parse: `torch torch_xla[tpu] -f https://storage.googleapis.com/libtpu-releases/index.html`\n  Caused by: Expected one of `@`, `(`, `<`, `=`, `>`, `~`, `!`, `;`, found `t`\ntorch torch_xla[tpu] -f https://storage.googleapis.com/libtpu-releases/index.html\n      ^"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.9.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/pytorch/xla","docs":null,"changelog":null,"pypi":"https://pypi.org/project/torch-xla/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","aws","gcp"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"install_fail","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-05","install_tag":null}}