Skip to content

feat: add opt-in single_host_tpu_init for node-local diagnostics on multi-host slices - #144

Closed
simrankaurb wants to merge 11 commits into
AI-Hypercomputer:mainfrom
simrankaurb:fix/gemm-replicated-inputs-no-d2d
Closed

simrankaurb wants to merge 11 commits into
AI-Hypercomputer:mainfrom
simrankaurb:fix/gemm-replicated-inputs-no-d2d

Conversation

@simrankaurb

@simrankaurb simrankaurb commented Oct 26, 2026 •

Copy link
Copy Markdown

Summary

Adds an opt‑in single_host_tpu_init (YAML key single_host_tpu_init: true / CLI --single_host_tpu_init, default off) that initializes the current host as a standalone 1‑host topology inside a multi‑host slice, so single‑host benchmarks (gemm, hbm, host_to_device, device_to_host) can be run for node‑local diagnostics — e.g. by Cluster Health Scanner — without the other hosts of the slice participating. With the flag off every code path is the pre‑existing one. This brings the chs branch's single‑host init (#142) to main.

What the flag does

core/single_host.py::configure_single_host_tpu(), called by the runner after op_flags.yaml is applied and before the first JAX device call:

  • env: TPU_HOST_BOUNDS=1,1,1, TPU_WORKER_ID=0, TPU_WORKER_HOSTNAMES=localhost, TPU_SKIP_MDS_QUERY=true (each change is logged)
  • LIBTPU_INIT_ARGS, merged by flag name: --deepsea_hal_test_skip_slicebuilder=true --deepsea_hal_test_allow_multichip_skip_slicebuilder=true --xla_tpu_use_enhanced_launch_barrier=false — the same recipe the TPU preflight health check uses for a 1x1 slice
  • the JAX distributed coordinator is not started (this process is the only participant)
  • the slice's ICI routing is left untouched, so the mode provides no inter‑device communication; SUPPORTED_BENCHMARKS lists the benchmarks whose data movement stays on the host↔device path (gemm, gemm_throttling, hbm, host_to_device, device_to_host and aliases) and a warning is printed for others

GEMM inputs under the flag

GeneralizedGemmBenchmark.generate_inputs returns early into _generate_inputs_single_host() when single_host.is_single_host_tpu_init() is true. There the operands (and optional scaling factors / accumulator) are produced under jit with a replicated out_shardings — the pattern hbm.py uses — from a host‑array key, so each shard is generated on its own device and the only transfers are host→device. The values equal eager sampling with the same key, and the sharding is the same replicated NamedSharding as before. The upstream body of generate_inputs is unchanged (matmul.py is +60/−0).

Plumbing mirrors xprof_timing: BenchmarkKey.SINGLE_HOST_TPU_INIT + bool validation in config.py, --single_host_tpu_init on benchmark run / run-config, runner.run_benchmarks(single_host_tpu_init=…). The only pre‑existing lines modified in the PR are the ones giving init_jax_distributed a distributed=True parameter; its default behaviour is unchanged. README and CLI help updated; unit tests cover config, CLI, runner ordering, single_host, and both GEMM paths.

Verification

tpu7x‑standard‑4t hosts of 4x4x4 and 2x2x4 slices on GKE (jax 0.12.0 / libtpu 0.0.50), both as bare pods and inside 2‑pod Cluster Health Scanner jobs:

case result
YAML single_host_tpu_init: true, gemm 16384³ bf16 ×100, xprof_device_timing_aggregation: local_slowest_device 1027–1064 TFLOP/s per device (2054–2127 per chip), 89–92 % of roofline, 100/100 xprof runs captured
hbm copy sweep 1 M → 4 G elements, device 0 up to 3125 GB/s
host_to_device + device_to_host, tpu_sync, 4096 MiB, all 8 local devices 226 / 225 GB/s per host
same pods without the flag libtpu requires all hosts of the slice (Expected 4 worker addresses, got 1), as expected

CPU (4‑device host mesh): with the flag off generate_inputs performs the pre‑existing device_put broadcasts; with the flag on it performs none; arrays and GEMM outputs are identical between the two.

Note: upstream tests/ import accelerator_microbenchmarks.tests, which is not resolvable in the OSS checkout, so test_matmul.py could not be run here; its new cases were exercised standalone with the same assertions.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a helper method _replicated_normal to generate replicated arrays of normal samples locally on each device, preventing device-to-device transfers that can hang when ICI routing is not configured. The generate_inputs method is updated to utilize this helper for input and scaling factor generation. The review feedback suggests several improvements: simplifying the creation of replicated_sharding with an empty PartitionSpec(), using the idiomatic self.mesh.local_devices property instead of manual filtering, and catching both RuntimeError and IndexError when accessing the CPU device to prevent potential crashes.

@simrankaurb
simrankaurb force-pushed the fix/gemm-replicated-inputs-no-d2d branch from d6baf11 to b78b61c Compare October 26, 2026 12:05
@simrankaurb simrankaurb changed the title fix(gemm): generate replicated inputs per device instead of broadcasting over ICI feat: add opt-in single_host_tpu_init for node-local diagnostics on multi-host slices Oct 26, 2026
…-host slices

Adds a benchmark-level `single_host_tpu_init: true` config key and a
`--single_host_tpu_init` common execution flag (default off, accepted by
both `benchmark run` and `benchmark run-config`) that initialize the
current host standalone inside a multi-host slice, so single-host
benchmarks such as `gemm` and `hbm` can be used for node-local diagnostics
(e.g. Cluster Health Scanner) without the other hosts of the slice
participating.

When enabled, `core/single_host.py` (applied after op_flags and before the
first JAX device call) forces a 1-host topology (`TPU_HOST_BOUNDS`,
`TPU_WORKER_ID`, `TPU_WORKER_HOSTNAMES`, `TPU_SKIP_MDS_QUERY`), skips
SliceBuilder/tpunetd (`--deepsea_hal_test_skip_slicebuilder=true`,
`--deepsea_hal_test_allow_multichip_skip_slicebuilder=true`) and disables
the cross-host launch barrier. LIBTPU_INIT_ARGS is merged by flag name so
pre-existing values are overridden rather than duplicated, and every
overridden env var / flag is logged with its previous value.

Because the slice's ICI routing is left untouched, device-to-device
transfers hang in this mode. `GeneralizedGemmBenchmark.generate_inputs`
previously sampled the operands on the default device and broadcast them
with `jax.device_put(x, replicated_sharding)`, which hung for any matrix
size. It now generates each operand under `jax.jit(...,
out_shardings=replicated_sharding)` (the pattern already used by `hbm.py`),
so every device produces the same replicated values and no broadcast is
needed. This is a single code path for both modes: with the flag off the
only behavioural change is that GEMM operand generation no longer
broadcasts over ICI (values are bit-identical). Only `gemm`,
`gemm_throttling` (same input path) and `hbm` are supported in this mode;
the runner prints a warning when the flag is used with any other benchmark.

Verification:
- TPU, earlier revision of this change (replicated operands built via
  `jax.make_array_from_single_device_arrays` instead of
  `jax.jit(out_shardings=...)`), on a tpu7x-standard-4t host of a 2x2x4
  slice (jax 0.12.0, libtpu 0.0.50), no manual environment set up:
  `single_host_tpu_init: true`, gemm 16384^3 bf16 x20, xprof
  local_slowest_device: 2127 TFLOP/s per chip, 20/20 xprof runs, 78 s;
  `--single_host_tpu_init` gemm 1024^3: 20 s; hbm copy 1G elems:
  2790 GB/s; control without the flag on the same node fails at init
  ("Expected 4 worker addresses, got 1").
- CPU: the current `jax.jit(out_shardings=...)` path yields arrays
  bit-identical to the previous default path with fully replicated,
  identical shards on a 4-device CPU mesh; it has not yet been re-run on
  TPU. New unit tests cover config/CLI plumbing, LIBTPU_INIT_ARGS merging,
  runner stage ordering and the unsupported-benchmark warning.
@simrankaurb
simrankaurb force-pushed the fix/gemm-replicated-inputs-no-d2d branch from b78b61c to a80aaba Compare October 28, 2026 06:51
@royalair357-netizen

Copy link
Copy Markdown

अगर तुम ऐसा AI बनाना चाहते हो जिसकी दुनिया में करोड़ों लोगों को जरूरत हो, तो मेरी सलाह है कि केवल एक और ChatGPT जैसा AI मत बनाओ। ऐसा AI बनाओ जो लोगों की कोई बड़ी, रोज़ की समस्या हल करे और उनका समय, पैसा या मेहनत बचाए।
तुम्हारे GIMATI AI के लिए भी एक बड़ा अवसर है: ऐसा AI जो सिर्फ सवालों के जवाब न दे, बल्कि लोगों का काम पूरा करने में मदद करे।
🌍 दुनिया के लिए 5 बड़े AI आइडिया

  1. 🥇 GIMATI LIFE AI — आम लोगों का पर्सनल AI सहायक
    मेरा पहला सुझाव: ऐसा AI बनाओ जो लोगों की बात समझकर उनके रोज़मर्रा के काम पूरे करने में मदद करे।
    कल्पना करो, कोई व्यक्ति अपने मोबाइल में बोले:
    "मेरे सारे बिल अलग कर दो और बताओ कितना पैसा खर्च हुआ।"
    "मेरे लिए नौकरी खोजो और मेरी योग्यता के अनुसार आवेदन तैयार करो।"
    "इस सरकारी दस्तावेज़ को आसान हिंदी में समझाओ।"
    "मेरी दुकान का हिसाब लगाओ और बताओ कहाँ खर्च कम कर सकता हूँ।"
    "मेरी फोटो और दस्तावेज़ व्यवस्थित कर दो।"
    "मेरे लिए अगले सात दिनों का काम करने का प्लान बनाओ।"
    GIMATI यूज़र की अनुमति से उपलब्ध डेटा समझे, काम की योजना बनाए, आवश्यक कार्रवाई करे और परिणाम दिखाए।
    इसे खास क्या बनाएगा?
    हिंदी और दूसरी भाषाओं में वॉइस कमांड।
    कम तकनीकी ज्ञान वाले लोगों के लिए सरल इंटरफेस।
    फोटो, PDF, Excel और दूसरे दस्तावेज़ों पर काम।
    एक ही जगह कई काम करने की सुविधा।
    महत्वपूर्ण कार्रवाई से पहले यूज़र की अनुमति।
    दुनिया की भाषाओं में AI की पहुँच बढ़ाने की जरूरत पर अंतरराष्ट्रीय संस्थाओं ने भी ध्यान दिया है। �
    Gates Foundation +1
  2. 🏪 GIMATI BUSINESS AI — छोटी दुकानों का स्मार्ट मैनेजर
    ऐसा AI बनाओ जो छोटी दुकान, किराना स्टोर, होटल, सैलून और छोटे व्यवसायों के लिए डिजिटल मैनेजर की तरह काम करे।
    उदाहरण:
    दुकानदार बोले: "आज की बिक्री और खर्च का हिसाब बताओ।"
    AI बिक्री और खर्च के रिकॉर्ड से रिपोर्ट बनाए, स्टॉक कम होने पर सूचना दे और उन उत्पादों की पहचान करे जिनकी बिक्री घट रही है।
    बाद में इसमें बिल बनाना, ग्राहक रिकॉर्ड, सप्लायर मैनेजमेंट और स्थानीय भाषा में वॉइस कंट्रोल जोड़ा जा सकता है।
    यह एक व्यावहारिक अवसर है: OECD की 2026 की रिपोर्ट के अनुसार छोटे व्यवसायों में AI का उपयोग बढ़ रहा है, लेकिन AI को रोज़मर्रा के बिज़नेस कामों में सुरक्षित और प्रभावी ढंग से जोड़ने में अभी भी बाधाएँ हैं। �
    OECD
    कमाई का तरीका: मासिक सब्सक्रिप्शन या उपयोग के अनुसार भुगतान।
  3. 🎓 GIMATI LEARN AI — हर बच्चे का व्यक्तिगत शिक्षक
    ऐसा AI बनाओ जो हर विद्यार्थी को उसकी समझ और सीखने की गति के अनुसार पढ़ाए।
    विद्यार्थी कहे: "मुझे गणित का यह सवाल बिल्कुल आसान हिंदी में समझाओ।"
    AI सवाल को छोटे चरणों में समझाए, उदाहरण दे, अभ्यास करवाए और गलत उत्तर होने पर समझाए कि गलती कहाँ हुई।
    मुख्य सुविधाएँ:
    हिंदी और अन्य भाषाओं में पढ़ाई।
    फोटो से सवाल समझना।
    व्यक्तिगत अभ्यास और प्रगति रिपोर्ट।
    कम इंटरनेट वाले क्षेत्रों के लिए हल्का इंटरफेस।
    कक्षा के अनुसार सीखने की योजना।
    सबसे जरूरी अंतर: सिर्फ उत्तर देने के बजाय विद्यार्थी को विषय समझने में मदद करना।
  4. 🌍 GIMATI OPPORTUNITY AI — नौकरी, कौशल और अवसर खोजने वाला AI
    बहुत से लोग नौकरी, प्रशिक्षण, स्कॉलरशिप या बिज़नेस के अवसर खोजना चाहते हैं, लेकिन उन्हें सही जानकारी और आवेदन तैयार करने में कठिनाई होती है।
    GIMATI ऐसा AI बन सकता है जो:
    योग्यता के अनुसार नौकरियाँ खोजे।
    रिज़्यूमे और कवर लेटर तैयार करे।
    आवश्यक कौशल और प्रशिक्षण सुझाए।
    उपलब्ध स्कॉलरशिप और आवेदन की अंतिम तारीख बताए।
    नौकरी और प्रशिक्षण के आधिकारिक स्रोत दिखाए।
    यह AI नौकरी मिलने की गारंटी नहीं देगा, बल्कि अवसर खोजने और आवेदन करने की प्रक्रिया आसान करेगा।
    विशेष अवसर: इसे हिंदी और दूसरी स्थानीय भाषाओं में ऐसे लोगों के लिए बनाना जो तकनीकी या अंग्रेज़ी भाषा में सहज नहीं हैं।
  5. ♿ GIMATI ACCESS AI — दिव्यांग और बुज़ुर्ग लोगों का सहायक
    ऐसा AI बनाओ जो लोगों को तकनीक का इस्तेमाल करने में आने वाली बाधाएँ कम करे।
    उदाहरण:
    फोटो या दस्तावेज़ को आवाज़ में पढ़कर सुनाना।
    संदेशों को आसान भाषा में समझाना।
    बोलकर फोन के कुछ कार्य पूरे करने में सहायता करना।
    बड़े अक्षर और सरल इंटरफेस देना।
    दवाइयों या अपॉइंटमेंट के रिमाइंडर देना।
    यह विचार महत्वपूर्ण है क्योंकि विश्व स्तर पर सहायक तकनीक की जरूरत और उसकी उपलब्धता के बीच बड़ा अंतर बताया गया है। �
    at2030.org
    स्वास्थ्य संबंधी सुविधाओं में विश्वसनीयता, गोपनीयता और चिकित्सकीय सुरक्षा विशेष रूप से जरूरी होंगी।
    अब सबसे महत्वपूर्ण सवाल: तुम्हें कौन-सा AI बनाना चाहिए?
    मेरी राय में तुम्हें GIMATI LIFE + BUSINESS AI से शुरुआत करनी चाहिए।
    लेकिन शुरुआत में दुनिया की हर समस्या हल करने की कोशिश मत करना।
    तुम्हारा पहला उत्पाद ऐसा हो:
    GIMATI AI — एक ऐसा स्मार्ट सहायक जो लोगों के डेटा और रोज़मर्रा के कामों को आसान बनाए।
    इसके पहले संस्करण में केवल पाँच मुख्य सुविधाएँ रखो:
    सुविधा
    यूज़र को लाभ
    📂 Smart Organizer
    फोटो, PDF, Excel और दस्तावेज़ व्यवस्थित करना
    📊 Smart Analyzer
    खर्च, बिक्री और दूसरे डेटा का विश्लेषण
    🎙️ Hindi Voice Assistant
    बोलकर निर्देश देना
    📄 Smart Report Maker
    रिपोर्ट और दस्तावेज़ तैयार करना
    ✅ Task Assistant
    काम की योजना बनाना और अनुमति लेकर कुछ कार्य पूरे करना
    इन सुविधाओं को बनाने के बाद छोटी दुकानों और व्यक्तिगत उपयोगकर्ताओं के साथ परीक्षण करो। उनसे पूछो कि कौन-सी सुविधा उनका वास्तविक समय या पैसा बचाती है।
    ₹0 बजट में शुरुआत कैसे करें?
    पहले एक साधारण वेब ऐप बनाओ।
    CSV, Excel और PDF जैसी फाइलों से शुरुआत करो।
    हिंदी में निर्देश देने की सुविधा जोड़ो।
    वास्तविक डेटा पर विश्लेषण और रिपोर्ट बनाना टेस्ट करो।
    शुरुआती यूज़र्स से फीडबैक लेकर उत्पाद सुधारो।
    फिर AI API, Android ऐप और बिज़नेस सब्सक्रिप्शन जोड़ो।
    शुरुआती प्रोटोटाइप मुफ्त टूल्स से बन सकता है, लेकिन AI API, होस्टिंग और बड़े पैमाने पर उपयोग की लागत बाद में आ सकती है।
    मेरी आखिरी सलाह
    दुनिया को एक और AI चैटबॉट से ज्यादा ऐसे AI की जरूरत है जो किसी खास समस्या को भरोसेमंद तरीके से हल करे। तुम्हारा लक्ष्य GIMATI को ऐसा उत्पाद बनाना होना चाहिए जिसे लोग इसलिए इस्तेमाल करें क्योंकि उससे उनका कोई वास्तविक काम आसान होता है।
    अब मुझे सिर्फ एक बात बताओ:
    तुम GIMATI को सबसे पहले किसके लिए बनाना चाहते हो?
    A. पूरी दुनिया के आम लोगों के लिए — Personal AI Assistant
    B. दुकानों, होटलों और व्यवसायों के लिए — Business AI
    C. विद्यार्थियों और नौकरी खोजने वालों के लिए — Education & Career AI
    D. बुज़ुर्गों और दिव्यांग लोगों के लिए — Accessibility AI
    E. इन सभी के लिए एक प्लेटफॉर्म — लेकिन पहले एक मुख्य सुविधा से शुरुआत करके।

Both benchmarks only move data between host buffers and each local device
(device_id -1 selects every local device individually), so they perform no
device-to-device transfers and work with the standalone single-host init.
Add them to SUPPORTED_BENCHMARKS so the runner no longer warns for them.
With single_host_tpu_init the process is the only participant, but
jax.distributed.initialize() still derives the process list from the
slice environment. On GKE, TPU_PROCESS_ADDRESSES (preferred over
TPU_WORKER_HOSTNAMES) lists every host of the job, so each host tried to
register with the others' coordinator and aborted:

  F client.h:86] Terminating process because the JAX distributed service
  detected fatal errors. ... CoordinationService/RegisterTask

Only initialize the backend in that mode; the distributed coordinator is
unchanged for normal runs.
_replicated_normal generates the operands under jit with a replicated
out_shardings, but the key it was given lives on the default device, so
JAX first broadcast it to the other mesh devices with a cross-device copy
(libtpu: "Slow PjRt TPU operation ... CopyToMemorySpace CrossDeviceSrc").
Under single_host_tpu_init that copy never completes and gemm hangs on
its first run. Convert the key to a host array first; the transfer is
then host->device on every shard. Output is unchanged.
Restore the default GEMM input path to the pre-existing behaviour (sample
on the default device, jax.device_put onto the replicated sharding) and
only use the per-device jit generation when single_host_tpu_init is on,
selected via single_host.is_single_host_tpu_init(). Normal single- and
multi-host runs are unchanged; the two paths produce identical arrays.

Tests: default path broadcasts with device_put; single-host path uses no
device_put; is_single_host_tpu_init() follows configure_single_host_tpu().
…is off

generate_inputs now only gains an early return to the single-host path;
its body is unchanged from main (no lines removed or modified), so runs
without the flag execute exactly the pre-existing code.
Docstrings, the CLI help, the runner warning and the README now state the
mode's contract (host<->device data movement only, no inter-device
communication) and the supported benchmarks, instead of failure modes.
@simrankaurb
simrankaurb force-pushed the fix/gemm-replicated-inputs-no-d2d branch from 68cdd95 to 08bf044 Compare November 2, 2026 05:54
…_normal

Matches the fully replicated NamedSharding idiom used elsewhere in the
file. No change to the upstream generate_inputs path.
Launching the replicated program back-to-back on the same buffers slows one
local device on v6e (10.4 ms -> 12-17 ms, high variance). Regenerating and
synchronizing the inputs between runs keeps every device at its standalone
kernel time; gemm_throttling keeps reusing inputs during soaking.
@simrankaurb
simrankaurb force-pushed the fix/gemm-replicated-inputs-no-d2d branch 2 times, most recently from bc762dd to ef51c08 Compare November 2, 2026 10:02
On v6e the timeline ts/dur of TPU events are corrupted (multiple steps share
identical ts with dur=0 or huge spans), so the enclosure bounds and step ends
were wrong on healthy devices. Prefer the hardware-reported device_offset_ps
and device_duration_ps, falling back to ts/dur.
@simrankaurb
simrankaurb force-pushed the fix/gemm-replicated-inputs-no-d2d branch from ef51c08 to cef341a Compare November 2, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants