Skip to content

Commit 4dc947b

Browse files
authored
[pallas] use torch.accelerator.synchronize() (#3013)
It is now supported by TorchTPU.
1 parent 759d06d commit 4dc947b

1 file changed

Lines changed: 2 additions & 28 deletions

File tree

helion/autotuner/benchmarking.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import torch
1818

1919
from ..runtime.settings import _env_get_bool
20-
from ..runtime.settings import _get_backend
2120
from ..runtime.settings import is_pallas_interpret
2221
from .progress_bar import iter_with_progress
2322
from helion._dist_utils import sync_object
@@ -138,33 +137,8 @@ def _get_tpu_tensors(result: object) -> list[torch.Tensor]:
138137

139138

140139
def synchronize_device(result: object = None) -> None:
141-
"""Wait for device computation to complete.
142-
143-
For TPU tensors, uses ``torch_tpu``'s tensor-level sync which truly
144-
blocks until the device finishes (``torch.accelerator.synchronize()``
145-
does not reliably wait on ``torch_tpu``). For all other cases, falls
146-
back to ``torch.accelerator.synchronize()``.
147-
"""
148-
tpu_tensors = _get_tpu_tensors(result)
149-
if tpu_tensors:
150-
try:
151-
from torch_tpu._internal.sync import ( # pyrefly: ignore[missing-import]
152-
synchronize as tpu_sync,
153-
)
154-
155-
tpu_sync(tpu_tensors, wait=True)
156-
return
157-
except ImportError:
158-
raise ImportError(
159-
"torch_tpu is required for reliable device synchronization on TPU. "
160-
"Install torch_tpu or torch.accelerator.synchronize() will return "
161-
"before device computation finishes, producing incorrect benchmarks."
162-
) from None
163-
if (
164-
not is_pallas_interpret()
165-
and _get_backend() != "pallas"
166-
and torch.accelerator.is_available()
167-
):
140+
"""Wait for device computation to complete."""
141+
if not is_pallas_interpret() and torch.accelerator.is_available():
168142
torch.accelerator.synchronize()
169143

170144

0 commit comments

Comments
 (0)