<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Svetlana Meissner</title>
    <description>The latest articles on DEV Community by Svetlana Meissner (@svetlana_meissner_ai).</description>
    <link>https://dev.to/svetlana_meissner_ai</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3835773%2F89e776ee-b543-47f4-913e-b0607429117a.png</url>
      <title>DEV Community: Svetlana Meissner</title>
      <link>https://dev.to/svetlana_meissner_ai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/svetlana_meissner_ai"/>
    <language>en</language>
    <item>
      <title>EvoSec-TorchTPU: 317 Faster Byzantine-Resilient FL &amp; Privacy Kernels on Cloud TPU v6e</title>
      <dc:creator>Svetlana Meissner</dc:creator>
      <pubDate>Tue, 01 Dec 2026 00:48:07 +0000</pubDate>
      <link>https://dev.to/svetlana_meissner_ai/evosec-torchtpu-317x-faster-byzantine-resilient-fl-privacy-kernels-on-cloud-tpu-v6e-40e0</link>
      <guid>https://dev.to/svetlana_meissner_ai/evosec-torchtpu-317x-faster-byzantine-resilient-fl-privacy-kernels-on-cloud-tpu-v6e-40e0</guid>
      <description>&lt;p&gt;Most PyTorch security and privacy libraries were written for CPUs and GPUs, relying on dynamic boolean masking (&lt;code&gt;updates[mask]&lt;/code&gt;), greedy Python loops, and ragged per-layer tensor slices.&lt;/p&gt;

&lt;p&gt;When we ported our &lt;strong&gt;IEEE CCNC 2027&lt;/strong&gt; Federated Learning defense research (&lt;em&gt;Evo-FedAgg&lt;/em&gt;) onto a live &lt;strong&gt;Google Cloud TPU &lt;code&gt;v6e-1&lt;/code&gt;&lt;/strong&gt; (&lt;code&gt;torch-tpu==0.3.0&lt;/code&gt;) for &lt;strong&gt;TorchTPU Sprint 2026 (&lt;code&gt;#TorchTPUSprint&lt;/code&gt;)&lt;/strong&gt;, naive PyTorch security code didn't just run slowly—it &lt;strong&gt;crashed on unimplemented ops, stalled for 55 seconds compiling, suffered &lt;code&gt;99.73%&lt;/code&gt; &lt;code&gt;bfloat16&lt;/code&gt; distance error, and exploded small Differential Privacy gradients by &lt;code&gt;1,256×&lt;/code&gt;!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we walk through the whole journey from first principles—no prior Federated Learning or TPU compiler background required:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Introduction:&lt;/strong&gt; What Federated Learning, Byzantine-Resilient Aggregation, and Differential Privacy actually are (and why they matter).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What We Evolved with AlphaEvolve:&lt;/strong&gt; The exact 3-line defenseless Python seed we started from, how &lt;strong&gt;live Google Cloud AlphaEvolve (&lt;code&gt;gemini-4-argon&lt;/code&gt;)&lt;/strong&gt; mutated it, and the two champion algorithms it discovered (&lt;code&gt;+108.5%&lt;/code&gt; and &lt;code&gt;+100.3%&lt;/code&gt; gains).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;7 Things That Broke on Cloud TPU &lt;code&gt;v6e-1&lt;/code&gt; (&lt;code&gt;torch-tpu 0.3.0&lt;/code&gt;)&lt;/strong&gt; and the exact static-shape PyTorch fixes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;How We Benchmarked Everything:&lt;/strong&gt; 4 TorchTPU execution modes + a custom &lt;strong&gt;Pallas VMEM kernel&lt;/strong&gt; (&lt;code&gt;@torch.tpu.pallas.jax_op&lt;/code&gt;) hitting &lt;strong&gt;&lt;code&gt;0.306 ms&lt;/code&gt;&lt;/strong&gt; (&lt;strong&gt;&lt;code&gt;316.8×&lt;/code&gt;&lt;/strong&gt; faster than Multi-Krum, &lt;strong&gt;&lt;code&gt;583K clients/sec&lt;/code&gt;&lt;/strong&gt; at &lt;code&gt;N=512&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The XProf Plot Twist:&lt;/strong&gt; Reading real XLA HLO hardware traces to see &lt;em&gt;why&lt;/em&gt; &lt;code&gt;torch.compile(backend="tpu")&lt;/code&gt; beat our first-pass Pallas kernel past &lt;code&gt;d = 512K&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;1-Click Colab (&lt;code&gt;v6e-1&lt;/code&gt;) + Gemma 4 E4B:&lt;/strong&gt; Run the full suite and live on-TPU adversarial co-evolution yourself.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Open-Source Repo &amp;amp; 1-Click Colab (&lt;code&gt;v6e-1&lt;/code&gt; TPU):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/Unisvet/evosec-torchtpu" rel="noopener noreferrer"&gt;https://github.com/Unisvet/evosec-torchtpu&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Colab Notebook:&lt;/strong&gt; &lt;a href="https://colab.research.google.com/github/Unisvet/evosec-torchtpu/blob/main/notebooks/EvoSec_TorchTPU_Sprint_2026.ipynb" rel="noopener noreferrer"&gt;Open EvoSec_TorchTPU_Sprint_2026.ipynb in Colab&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  1. Intro: Federated Learning, Byzantine Attacks &amp;amp; Privacy
&lt;/h2&gt;

&lt;p&gt;If you've never worked on distributed AI security before, here is the 60-second intuition:&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Federated Learning (FL)?
&lt;/h3&gt;

&lt;p&gt;Imagine 200 hospitals, smartphones, or edge IoT sensors that want to train &lt;strong&gt;one shared AI model&lt;/strong&gt; together—&lt;em&gt;without ever uploading their private raw data&lt;/em&gt; to the cloud.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Every round, each device trains locally on its own private data and computes a &lt;strong&gt;model update&lt;/strong&gt; (a flat vector of &lt;code&gt;d&lt;/code&gt; numbers showing which direction to nudge the shared model's weights).&lt;/li&gt;
&lt;li&gt;All &lt;code&gt;N&lt;/code&gt; devices send only their update vectors &lt;code&gt;U&lt;/code&gt; (a matrix of shape &lt;code&gt;[N, d]&lt;/code&gt;) to a central &lt;strong&gt;aggregator&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The aggregator combines them into one clean global update—usually by taking a simple average (&lt;strong&gt;FedAvg&lt;/strong&gt;).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What does "Byzantine-Resilient" mean?
&lt;/h3&gt;

&lt;p&gt;Because the central server &lt;strong&gt;never sees the raw local data&lt;/strong&gt;, it cannot verify whether a device is telling the truth. What if &lt;strong&gt;30%–40% of the devices are hacked, broken, or actively malicious&lt;/strong&gt;?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Gaussian Noise Storm:&lt;/strong&gt; Rogue nodes blast huge random numbers that drown out the average.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sign-Flip ("Flipped Compass"):&lt;/strong&gt; Rogue nodes send the exact &lt;em&gt;opposite&lt;/em&gt; of the true gradient to push the model backwards.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sybil Gang ("Fake Choir"):&lt;/strong&gt; Hacked nodes collude and send identical poisoned vectors to outvote honest devices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ALIE &amp;amp; Orthogonal-Projection Stealth:&lt;/strong&gt; Subtle attackers hide inside the statistical variance of honest updates—or inject poison &lt;em&gt;orthogonal&lt;/em&gt; to the current global model direction—so simple distance or norm filters miss them!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A &lt;strong&gt;Byzantine-resilient aggregator&lt;/strong&gt; acts like a mathematical &lt;em&gt;Maxwell's Demon&lt;/em&gt;: using only the geometry of the &lt;code&gt;N&lt;/code&gt; update vectors, it spots and discards the saboteurs while preserving honest diverse voices.&lt;/p&gt;

&lt;h3&gt;
  
  
  What about Gradient Privacy (DLG Attacks)?
&lt;/h3&gt;

&lt;p&gt;Even if all devices are honest, a curious server can run a &lt;strong&gt;Deep Leakage from Gradients (DLG / iDLG)&lt;/strong&gt; attack—inverting a client's shared gradient vector back into their private training image! Adding &lt;strong&gt;Differential Privacy (DP)&lt;/strong&gt; noise blocks this inversion, &lt;em&gt;but&lt;/em&gt; naive uniform DP-SGD destroys training accuracy. We want &lt;strong&gt;high reconstruction MSE&lt;/strong&gt; (attacker fails to recover the image) &lt;em&gt;and&lt;/em&gt; &lt;strong&gt;high gradient cosine similarity&lt;/strong&gt; (model still learns accurately).&lt;/p&gt;




&lt;h2&gt;
  
  
  2. What Code Did We Evolve with Live AlphaEvolve?
&lt;/h2&gt;

&lt;p&gt;Instead of hand-tuning brittle defense heuristics, we used &lt;strong&gt;Google Cloud AlphaEvolve&lt;/strong&gt; (&lt;code&gt;ae 0.2.8&lt;/code&gt;, powered by &lt;code&gt;gemini-4-argon&lt;/code&gt;) to evolve &lt;strong&gt;pure Python/NumPy defense algorithms offline&lt;/strong&gt;, guided by a multi-objective fitness judge.&lt;/p&gt;

&lt;h3&gt;
  
  
  Experiment 1 (&lt;code&gt;evo_fedagg_tpu&lt;/code&gt;): Evolving a Byzantine Aggregator from Zero Defense Hints
&lt;/h3&gt;

&lt;p&gt;We started AlphaEvolve from a &lt;strong&gt;3-line, completely defenseless FedAvg seed&lt;/strong&gt; (&lt;code&gt;prog-cream-silkworm&lt;/code&gt;, score &lt;code&gt;94.55 / 200&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Seed G0 (defenseless baseline fed to AlphaEvolve — zero defense hints!)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;aggregate_updates&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;updates&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;weights&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;global_model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;alpha&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;w&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;weights&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weights&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;1e-12&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;updates&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;axis&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every time AlphaEvolve proposed a mutated Python function, our automated evaluator graded it across &lt;strong&gt;5 tough criteria&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Clean Accuracy&lt;/strong&gt; (don't hurt learning when nobody is attacking).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Classic Byzantine Arena&lt;/strong&gt; (Gaussian noise, Sign-Flip, and Sybil gangs at 30% corruption).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stealth Arena&lt;/strong&gt; (ALIE variance-hiding + targeted &lt;strong&gt;Orthogonal-Projection Stealth&lt;/strong&gt; attacks).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;bfloat16&lt;/code&gt; Numerical Stability&lt;/strong&gt; (simulating Cloud TPU &lt;code&gt;bf16&lt;/code&gt; rounding &amp;amp; cancellation).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TPU Static-Shape AST Audit + Speed Timer&lt;/strong&gt; (automatically penalizing Python loops over &lt;code&gt;N&lt;/code&gt; and dynamic boolean indexing like &lt;code&gt;updates[mask]&lt;/code&gt; that break XLA compilation!).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhk8oqi8lbnm3px6cq9jd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fhk8oqi8lbnm3px6cq9jd.png" alt="Live AlphaEvolve Progression" width="800" height="288"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Across 30 successful evaluations (&lt;code&gt;exp-vigorous-crayfish&lt;/code&gt;), AlphaEvolve climbed from &lt;strong&gt;&lt;code&gt;94.55&lt;/code&gt; → &lt;code&gt;197.16 / 200&lt;/code&gt; (&lt;code&gt;+108.5%&lt;/code&gt;)&lt;/strong&gt; and invented champion &lt;strong&gt;&lt;code&gt;prog-deft-cuscus&lt;/code&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Attack error dropped from &lt;code&gt;10.3813&lt;/code&gt; → &lt;code&gt;0.0005&lt;/code&gt;&lt;/strong&gt; on classic attacks, &lt;strong&gt;&lt;code&gt;0.0005&lt;/code&gt;&lt;/strong&gt; on ALIE, &lt;strong&gt;&lt;code&gt;0.0005&lt;/code&gt;&lt;/strong&gt; on orthogonal-projection stealth, and &lt;strong&gt;&lt;code&gt;9.2973&lt;/code&gt; → &lt;code&gt;0.0007&lt;/code&gt;&lt;/strong&gt; under &lt;code&gt;bfloat16&lt;/code&gt;!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The TPU-friendly mathematical trick AlphaEvolve invented:&lt;/strong&gt; Naive orthogonal-subspace detectors project every client vector onto the subspace perpendicular to the global model &lt;code&gt;g_hat&lt;/code&gt; and compute a &lt;em&gt;second&lt;/em&gt; expensive &lt;code&gt;O(N²·d)&lt;/code&gt; matrix multiply. Instead, &lt;code&gt;prog-deft-cuscus&lt;/code&gt; computes the Gram matrix &lt;strong&gt;&lt;code&gt;G = U @ U.T&lt;/code&gt; once&lt;/strong&gt; on the &lt;code&gt;bf16&lt;/code&gt; MXU, and derives all orthogonal-subspace distances purely via exact &lt;strong&gt;&lt;code&gt;O(N²)&lt;/code&gt; rank-1 updates&lt;/strong&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p[i]   = dot(u[i], g_hat)           # 1D projection onto global model direction
G_perp = G - outer(p, p)            # Exact O(N²) rank-1 Gram update (no 2nd O(N²·d) matmul!)
D_perp = sqrt(max(0, diag(G_perp) + diag(G_perp).T - 2 * G_perp))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It then combines de-cloned &lt;code&gt;k&lt;/code&gt;-NN geometry with a smooth &lt;strong&gt;Landau phase-transition gate&lt;/strong&gt;—meaning &lt;strong&gt;zero dynamic boolean masks&lt;/strong&gt; and &lt;strong&gt;100% static tensor shapes&lt;/strong&gt; for Cloud TPU!&lt;/p&gt;

&lt;h3&gt;
  
  
  Experiment 2 (&lt;code&gt;evo_privedge_tpu&lt;/code&gt;): Evolving a Privacy-Preserving DP Sanitizer
&lt;/h3&gt;

&lt;p&gt;In parallel (&lt;code&gt;exp-apricot-crane&lt;/code&gt;), we started from a standard &lt;strong&gt;Uniform DP-SGD&lt;/strong&gt; seed (&lt;code&gt;71.95 / 150&lt;/code&gt;) and evaluated candidates against a &lt;strong&gt;real 2-layer tanh MLP DLG / iDLG gradient-inversion attacker&lt;/strong&gt; plus a &lt;code&gt;bfloat16&lt;/code&gt; small-gradient stability test.&lt;/p&gt;

&lt;p&gt;AlphaEvolve climbed to &lt;strong&gt;&lt;code&gt;144.12 / 150&lt;/code&gt; (&lt;code&gt;+100.3%&lt;/code&gt;)&lt;/strong&gt; with champion &lt;strong&gt;&lt;code&gt;prog-pompous-orangutan&lt;/code&gt;&lt;/strong&gt;, inventing &lt;strong&gt;Scale-Invariant Weighted Gram-Schmidt Orthogonalized Noise&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It applies stronger structured noise to high-leakage input-layer weights (breaking the rank-1 outer-product leakage that iDLG exploits),&lt;/li&gt;
&lt;li&gt;Projects the noise &lt;em&gt;orthogonal&lt;/em&gt; to the useful gradient direction so training stays sharp (&lt;code&gt;0.9692&lt;/code&gt; cosine similarity vs &lt;code&gt;0.7304&lt;/code&gt; baseline),&lt;/li&gt;
&lt;li&gt;Preserves exact gradient norms (&lt;code&gt;norm_fidelity = 1.0000&lt;/code&gt;, &lt;code&gt;bf16_stability = 1.000&lt;/code&gt;, &lt;code&gt;DLG MSE = 2.9059&lt;/code&gt; vs &lt;code&gt;1.0411&lt;/code&gt; baseline).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Seven Things That Actually Broke on Cloud TPU &lt;code&gt;v6e-1&lt;/code&gt; (&lt;code&gt;torch-tpu 0.3.0&lt;/code&gt;)
&lt;/h2&gt;

&lt;p&gt;Next, we ported both AlphaEvolve champions—plus naive PyTorch baselines—into our reusable &lt;a href="https://github.com/Unisvet/evosec-torchtpu/tree/main/src/evosec_tpu" rel="noopener noreferrer"&gt;&lt;code&gt;evosec_tpu&lt;/code&gt;&lt;/a&gt; package and ran them live on a &lt;strong&gt;Google Cloud TPU &lt;code&gt;v6e-1&lt;/code&gt;&lt;/strong&gt; VM (&lt;code&gt;europe-west4-a&lt;/code&gt;, &lt;code&gt;v2-alpha-tpuv6e&lt;/code&gt;, &lt;code&gt;torch-tpu==0.3.0&lt;/code&gt;, &lt;code&gt;torch==2.15.0+cpu&lt;/code&gt;, &lt;code&gt;jax==0.10.2&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Here are the &lt;strong&gt;7 real failure modes&lt;/strong&gt; we hit and fixed:&lt;/p&gt;

&lt;h3&gt;
  
  
  4 Algorithmic &amp;amp; &lt;code&gt;bfloat16&lt;/code&gt; Numerical Traps
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Boolean Indexing (&lt;code&gt;U[keep_mask]&lt;/code&gt;):&lt;/strong&gt;&lt;br&gt;
Classic Z-score filters select survivors via &lt;code&gt;U[z &amp;lt; 2.5]&lt;/code&gt;. Because the number of surviving rows changes every round, XLA cannot keep a static graph and stalls on host-device syncs—burning &lt;strong&gt;&lt;code&gt;230.8 ms&lt;/code&gt;&lt;/strong&gt; inside &lt;code&gt;aten::_to_copy&lt;/code&gt; across 8 steps (&lt;code&gt;32.16 ms/step&lt;/code&gt;).&lt;br&gt;
&lt;strong&gt;Fix:&lt;/strong&gt; Keep shapes static! Compute soft &lt;code&gt;[N]&lt;/code&gt; weights with &lt;code&gt;torch.where&lt;/code&gt; + &lt;code&gt;torch.topk&lt;/code&gt;/&lt;code&gt;torch.sort&lt;/code&gt; and reduce via &lt;code&gt;w @ U&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Greedy Multi-Krum Python Loop (&lt;code&gt;O(m·N²·d)&lt;/code&gt;):&lt;/strong&gt;&lt;br&gt;
Standard Multi-Krum loops in Python &lt;code&gt;m = N - f&lt;/code&gt; times updating selection masks. On Cloud TPU &lt;code&gt;v6e-1&lt;/code&gt;, warmup compilation thrashed for &lt;strong&gt;&lt;code&gt;47.2 s&lt;/code&gt;–&lt;code&gt;55.5 s&lt;/code&gt;&lt;/strong&gt; at &lt;code&gt;N=64–128, d=65,536&lt;/code&gt;, and steady-state latency crawled at &lt;strong&gt;&lt;code&gt;96.81 ms&lt;/code&gt;&lt;/strong&gt;.&lt;br&gt;
&lt;strong&gt;Fix:&lt;/strong&gt; Single-pass &lt;code&gt;bf16&lt;/code&gt; MXU Gram matmul + rank-1 &lt;code&gt;O(N²)&lt;/code&gt; updates (&lt;code&gt;0.306 ms&lt;/code&gt; compiled—&lt;strong&gt;&lt;code&gt;316.8×&lt;/code&gt; faster&lt;/strong&gt;!).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Catastrophic &lt;code&gt;bfloat16&lt;/code&gt; Cancellation in Pairwise Distances:&lt;/strong&gt;&lt;br&gt;
Honest FL updates cluster closely around the true descent direction. Computing &lt;code&gt;sq + sq.T - 2 * (U @ U.T)&lt;/code&gt; directly in &lt;code&gt;bfloat16&lt;/code&gt; (only 7 mantissa bits!) wipes out the small difference between large squared norms:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="c1"&gt;# BROKEN on TPU bf16: 99.73% relative distance error on clustered FL updates!&lt;/span&gt;
   &lt;span class="n"&gt;sq&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u_bf16&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;u_bf16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dim&lt;/span&gt;&lt;span class="o"&gt;=-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;keepdim&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="n"&gt;dmat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sq&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;sq&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u_bf16&lt;/span&gt; @ &lt;span class="n"&gt;u_bf16&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Measured on &lt;code&gt;v6e-1&lt;/code&gt;:&lt;/strong&gt; &lt;strong&gt;&lt;code&gt;99.73%&lt;/code&gt;&lt;/strong&gt; relative distance error vs &lt;code&gt;fp32&lt;/code&gt; &lt;code&gt;torch.cdist&lt;/code&gt;!&lt;br&gt;
   &lt;strong&gt;Fix:&lt;/strong&gt; Scale-normalize inputs before the &lt;code&gt;bf16&lt;/code&gt; MXU dot product, accumulate Gram entries and squared norms in &lt;code&gt;fp32&lt;/code&gt;, and clamp &lt;code&gt;&amp;gt;= 0.0&lt;/code&gt; before &lt;code&gt;sqrt&lt;/code&gt; (&lt;code&gt;0.0%&lt;/code&gt; NaN, &lt;code&gt;&amp;lt; 0.0023&lt;/code&gt; aggregation error).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Small-Gradient &lt;code&gt;bfloat16&lt;/code&gt; DP Underflow (&lt;code&gt;1,256×&lt;/code&gt; Norm Explosion):&lt;/strong&gt;
Slicing ragged layer views (&lt;code&gt;g[:, start:end]&lt;/code&gt;) and clipping &lt;code&gt;1e-4&lt;/code&gt; late-stage gradients in &lt;code&gt;bf16&lt;/code&gt; underflows the norm and explodes output norms by &lt;strong&gt;&lt;code&gt;1,255.95×&lt;/code&gt;&lt;/strong&gt;!
&lt;strong&gt;Fix:&lt;/strong&gt; Precompute contiguous &lt;code&gt;[1, d]&lt;/code&gt; static layer masks and run scale-invariant &lt;code&gt;fp32&lt;/code&gt; orthogonal DP—achieving &lt;strong&gt;&lt;code&gt;0.9999×&lt;/code&gt;&lt;/strong&gt; exact norm fidelity!&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  3 Real &lt;code&gt;torch-tpu 0.3.0&lt;/code&gt; Platform Gotchas (Field Notes)
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Use &lt;code&gt;torch.accelerator&lt;/code&gt;, NOT &lt;code&gt;torch.tpu.is_available()&lt;/code&gt;:&lt;/strong&gt;
In &lt;code&gt;torch-tpu 0.3.0&lt;/code&gt;, &lt;code&gt;torch.tpu.is_available()&lt;/code&gt; raises a &lt;code&gt;RuntimeError&lt;/code&gt; ("internal to TorchTPU"). Use PyTorch's portable accelerator API instead:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;   &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torch_tpu&lt;/span&gt;  &lt;span class="c1"&gt;# noqa: F401 - registers PrivateUse1 -&amp;gt; 'tpu'&lt;/span&gt;
   &lt;span class="n"&gt;is_tpu&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;accelerator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_available&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;accelerator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;current_accelerator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"tpu"&lt;/span&gt;
   &lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;accelerator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;synchronize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;aten::median&lt;/code&gt; is not yet implemented on TPU (&lt;code&gt;torch-tpu 0.3.0&lt;/code&gt;):&lt;/strong&gt;
Calling &lt;code&gt;torch.median(x, dim=0)&lt;/code&gt; raises &lt;code&gt;RuntimeError: operator 'aten::median' is not implemented for TPU&lt;/code&gt;—immediately breaking Coordinate Median and MAD defenses. Replacing it with a static-shape &lt;code&gt;torch.sort&lt;/code&gt;-based &lt;code&gt;tpu_median()&lt;/code&gt; works cleanly in both eager and &lt;code&gt;torch.compile(backend="tpu")&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pallas &lt;code&gt;jax_op&lt;/code&gt;, &lt;code&gt;/dev/vfio/0&lt;/code&gt;, and Dual Profiler Isolation:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Avoid &lt;code&gt;from __future__ import annotations&lt;/code&gt; in files defining &lt;code&gt;@torch.tpu.pallas.jax_op&lt;/code&gt; when &lt;code&gt;jax&lt;/code&gt; is imported lazily (TorchTPU evaluates annotations with &lt;code&gt;eval_str=True&lt;/code&gt;, throwing &lt;code&gt;NameError: name 'jax' is not defined&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Single-chip TPU &lt;code&gt;v6e-1&lt;/code&gt; locks &lt;code&gt;/dev/vfio/0&lt;/code&gt; to one process at a time—run &lt;code&gt;TORCH_TPU_DEFER_AND_FUSE=1&lt;/code&gt; as a sequential standalone command, not a child subprocess.&lt;/li&gt;
&lt;li&gt;Never start &lt;code&gt;jax.profiler.start_trace()&lt;/code&gt; inside an active &lt;code&gt;torch.profiler.profile(activities=[..., TPU])&lt;/code&gt; block (triggers libtpu &lt;code&gt;periodicclosure.cc:33&lt;/code&gt; SIGABRT). Run &lt;code&gt;torch.profiler&lt;/code&gt; and &lt;code&gt;jax.profiler&lt;/code&gt; sequentially!&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  4. How We Benchmarked All 4 TorchTPU Modes + Custom Pallas VMEM
&lt;/h2&gt;

&lt;p&gt;To understand how PyTorch security kernels actually scale on Cloud TPU &lt;code&gt;v6e-1&lt;/code&gt;, we built a three-layer benchmark suite:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Microbenchmarks (&lt;code&gt;benchmarks/run_tpu_modes.py&lt;/code&gt;):&lt;/strong&gt; Sweeps &lt;strong&gt;8 realistic &lt;code&gt;(N, d)&lt;/code&gt; Federated Learning workloads&lt;/strong&gt;—from small edge models (&lt;code&gt;N=20, d=7,850&lt;/code&gt;) and 128-aligned MXU tiles (&lt;code&gt;N=128, d=65,536&lt;/code&gt;) up to 0.5M–1M parameter HBM stress tests (&lt;code&gt;N=256, d=1,048,576&lt;/code&gt;) and large cohorts (&lt;code&gt;N=512, d=65,536&lt;/code&gt;)—measuring warmup time, steady-state median (&lt;code&gt;15&lt;/code&gt; iterations), p95 latency, throughput (&lt;code&gt;clients/sec&lt;/code&gt;), and accuracy error vs the honest mean.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Execution Modes Tested:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Naive Broken PyTorch:&lt;/strong&gt; Greedy Multi-Krum loop &amp;amp; Dynamic Boolean Z-Mask.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TorchTPU Strict Eager (&lt;code&gt;TORCH_TPU_DEFER_AND_FUSE=0&lt;/code&gt;):&lt;/strong&gt; Static-shape &lt;code&gt;v2&lt;/code&gt; champion executed op-by-op.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TorchTPU DeferAndFuse (&lt;code&gt;TORCH_TPU_DEFER_AND_FUSE=1&lt;/code&gt;):&lt;/strong&gt; Fused eager mode.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;torch.compile(backend="tpu", dynamic=False)&lt;/code&gt;:&lt;/strong&gt; Full XLA compiler lowering and fusion.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Custom Block-Fused Pallas VMEM Kernel (&lt;code&gt;@torch.tpu.pallas.jax_op&lt;/code&gt;):&lt;/strong&gt; Hand-written &lt;code&gt;(128, 128)&lt;/code&gt; Mosaic VMEM tiled Gram + statistics kernel in &lt;a href="https://github.com/Unisvet/evosec-torchtpu/blob/main/src/evosec_tpu/pallas_kernel.py" rel="noopener noreferrer"&gt;&lt;code&gt;pallas_kernel.py&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hardware Profiling (&lt;code&gt;benchmarks/run_xprof_capture.py&lt;/code&gt;) &amp;amp; End-to-End FL/DLG (&lt;code&gt;benchmarks/run_fl_benchmarks.py&lt;/code&gt;):&lt;/strong&gt; Captures real TPU XLA HLO traces + real non-IID MNIST training and DLG image-inversion curves.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frymyg9h1jdn7r0p6n2j1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Frymyg9h1jdn7r0p6n2j1.png" alt="TorchTPU 4-Mode Scaling on Cloud TPU v6e-1" width="799" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Measured Steady-State Latency on Cloud TPU &lt;code&gt;v6e-1&lt;/code&gt; (&lt;code&gt;0&lt;/code&gt; unbounded dynamic compilations)
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;
&lt;code&gt;(N, d)&lt;/code&gt; Workload&lt;/th&gt;
&lt;th&gt;Naive Multi-Krum&lt;/th&gt;
&lt;th&gt;Naive Z-Mask &lt;em&gt;(err)&lt;/em&gt;
&lt;/th&gt;
&lt;th&gt;Strict Eager (&lt;code&gt;v2&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;DeferAndFuse (&lt;code&gt;v2&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;Pallas VMEM (&lt;code&gt;jax_op&lt;/code&gt;)&lt;/th&gt;
&lt;th&gt;&lt;code&gt;torch.compile(tpu)&lt;/code&gt;&lt;/th&gt;
&lt;th&gt;Speedup&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;(20, 7,850)&lt;/code&gt; &lt;em&gt;(Edge Ref)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;9.56 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;1.30 ms&lt;/code&gt; &lt;em&gt;(0.307)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;4.23 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3.02 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0.362 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;0.213 ms&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;45.0×&lt;/strong&gt; vs MK&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;(32, 8,192)&lt;/code&gt; &lt;em&gt;(Small Tile)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;16.55 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;1.32 ms&lt;/code&gt; &lt;em&gt;(0.274)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5.03 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2.59 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;0.234 ms&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;0.210 ms&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;78.8×&lt;/strong&gt; vs MK / &lt;strong&gt;23.9×&lt;/strong&gt; vs Eager&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;(64, 65,536)&lt;/code&gt; &lt;em&gt;(CNN/LoRA)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;45.48 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;1.89 ms&lt;/code&gt; &lt;em&gt;(0.371)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;4.38 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2.62 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0.383 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;0.260 ms&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;175.0×&lt;/strong&gt; vs MK&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;(128, 65,536)&lt;/code&gt; &lt;em&gt;(MXU Tile)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;96.81 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;2.89 ms&lt;/code&gt; &lt;em&gt;(0.318)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;4.15 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;2.89 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;0.422 ms&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;0.306 ms&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;316.8×&lt;/strong&gt; vs MK (&lt;code&gt;418.8K cli/s&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;(512, 65,536)&lt;/code&gt; &lt;em&gt;(Large Cohort)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;em&gt;skipped&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;9.11 ms&lt;/code&gt; &lt;em&gt;(0.274)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5.23 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;3.48 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5.17 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;0.878 ms&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;10.4×&lt;/strong&gt; vs Z-Mask (&lt;code&gt;583.1K cli/s&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;(128, 524,288)&lt;/code&gt; &lt;em&gt;(0.5M Params)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;em&gt;skipped&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;15.70 ms&lt;/code&gt; &lt;em&gt;(0.597)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;6.49 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5.32 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;5.46 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;2.37 ms&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;6.6×&lt;/strong&gt; vs Z-Mask&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;(256, 524,288)&lt;/code&gt; &lt;em&gt;(XProf Scale)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;em&gt;skipped&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;32.04 ms&lt;/code&gt; &lt;em&gt;(0.459)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;10.20 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;8.57 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;14.31 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;4.71 ms&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;6.8×&lt;/strong&gt; vs Z-Mask&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;(256, 1,048,576)&lt;/code&gt; &lt;em&gt;(1M HBM)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;em&gt;skipped&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;63.60 ms&lt;/code&gt; &lt;em&gt;(0.596)&lt;/em&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;20.14 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;15.17 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;28.70 ms&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;9.21 ms&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;6.9×&lt;/strong&gt; vs Z-Mask&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Look at that textbook TorchTPU ladder at &lt;code&gt;N=128, d=65,536&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Naive Multi-Krum (&lt;code&gt;96.81 ms&lt;/code&gt;)&lt;/strong&gt; → &lt;strong&gt;Strict Eager (&lt;code&gt;4.15 ms&lt;/code&gt;)&lt;/strong&gt; → &lt;strong&gt;DeferAndFuse (&lt;code&gt;2.89 ms&lt;/code&gt;, &lt;code&gt;1.44×&lt;/code&gt; over Eager)&lt;/strong&gt; → &lt;strong&gt;Custom Pallas VMEM (&lt;code&gt;0.422 ms&lt;/code&gt;, &lt;code&gt;230×&lt;/code&gt; over MK)&lt;/strong&gt; → &lt;strong&gt;&lt;code&gt;torch.compile(backend="tpu")&lt;/code&gt; (&lt;code&gt;0.306 ms&lt;/code&gt;, &lt;code&gt;317×&lt;/code&gt; over MK!)&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  5. The XProf Plot Twist: Why &lt;code&gt;torch.compile&lt;/code&gt; Beat Our First-Pass Pallas Kernel at &lt;code&gt;d = 512K&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;This was our favorite engineering lesson of the sprint. Up to &lt;code&gt;d = 65K&lt;/code&gt;, our custom Pallas VMEM kernel (&lt;code&gt;0.234–0.422 ms&lt;/code&gt;) ran nearly neck-and-neck with &lt;code&gt;torch.compile(backend="tpu")&lt;/code&gt;. So why did Pallas slow to &lt;code&gt;14.31–16.10 ms&lt;/code&gt; at &lt;code&gt;(N=256, d=524,288)&lt;/code&gt; while &lt;code&gt;torch.compile&lt;/code&gt; flew at &lt;strong&gt;&lt;code&gt;4.71 ms&lt;/code&gt;&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd0i8nv29gmm3vnbkgw21.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd0i8nv29gmm3vnbkgw21.png" alt="XProf / torch.profiler Breakdown on TPU v6e-1" width="800" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our real &lt;code&gt;torch.profiler&lt;/code&gt; (&lt;code&gt;TpuKinetoProfilerSession&lt;/code&gt;, 5 XSpace planes) and native XProf &lt;code&gt;.xplane.pb&lt;/code&gt; captures (&lt;a href="https://github.com/Unisvet/evosec-torchtpu/blob/main/xprof_traces/xprof_summary.json" rel="noopener noreferrer"&gt;&lt;code&gt;xprof_summary.json&lt;/code&gt;&lt;/a&gt;) answered the question directly in the XLA HLO IR:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Naive Z-Mask (&lt;code&gt;32.16 ms/step&lt;/code&gt;):&lt;/strong&gt; &lt;code&gt;aten::_to_copy&lt;/code&gt; stalled the host CPU for &lt;strong&gt;&lt;code&gt;230.8 ms&lt;/code&gt;&lt;/strong&gt; (8 steps), while &lt;code&gt;tt_jit_sort&lt;/code&gt; (&lt;code&gt;193.6 ms&lt;/code&gt;) and &lt;code&gt;X64Combine&lt;/code&gt; (&lt;code&gt;53.7 ms&lt;/code&gt;) thrashed HBM transposing &lt;code&gt;f32[256, 524288]&lt;/code&gt; layouts back and forth.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;torch.compile(backend="tpu")&lt;/code&gt; (&lt;code&gt;4.75 ms/step&lt;/code&gt;):&lt;/strong&gt; XLA collapsed the entire evolved aggregator into &lt;strong&gt;one fused executable&lt;/strong&gt; (&lt;code&gt;aggregators_L130_split0_fwd&lt;/code&gt;, &lt;code&gt;4.48 ms/step&lt;/code&gt; pure TPU time), streaming native &lt;code&gt;bf16[256, 524288]{1,0:T(8,128)(2,1)}&lt;/code&gt; tiles into the MXU with asynchronous VMEM prefetch (&lt;code&gt;copy-start&lt;/code&gt; / &lt;code&gt;copy-done&lt;/code&gt; into &lt;code&gt;:S(1)&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pallas VMEM (&lt;code&gt;16.10 ms/step&lt;/code&gt; at &lt;code&gt;512K&lt;/code&gt;):&lt;/strong&gt; XProf showed our two custom Mosaic calls:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   %fused_vmem_gram_and_stats.2 = f32[256,256] custom-call(bf16[256,524288], ...), target="tpu_custom_call"  (55.36 ms / 8 steps)
   %fused_vmem_gram_and_stats.3 = f32[256,128] custom-call(bf16[256,524288], bf16[8,524288]), target="tpu_custom_call" (21.43 ms / 8 steps)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Plus &lt;code&gt;55.5 ms&lt;/code&gt; stalled on synchronous &lt;code&gt;copy-start&lt;/code&gt; DMA barriers! Because our first-pass Pallas &lt;code&gt;jax_op&lt;/code&gt; launched &lt;strong&gt;two separate&lt;/strong&gt; &lt;code&gt;tpu_custom_call&lt;/code&gt; passes over HBM without double-buffered &lt;code&gt;d&lt;/code&gt;-tile pipelining, XLA's compiler-pipelined &lt;code&gt;bf16&lt;/code&gt; fusion beat it once HBM bandwidth dominated past &lt;code&gt;d = 512K&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Golden rule for TorchTPU developers:&lt;/strong&gt; Fix dynamic shapes and &lt;code&gt;bf16&lt;/code&gt; numerics first, turn on &lt;code&gt;torch.compile(backend="tpu", dynamic=False)&lt;/code&gt;, and &lt;strong&gt;always inspect XProf HLO traces&lt;/strong&gt; before hand-writing multi-buffered Pallas kernels!&lt;/p&gt;




&lt;h2&gt;
  
  
  6. End-to-End FL Resilience, DLG Privacy Frontier &amp;amp; Gemma 4 E4B on Colab
&lt;/h2&gt;

&lt;p&gt;Does TPU acceleration weaken real-world security or privacy? We verified on &lt;strong&gt;real Non-IID MNIST Federated Learning&lt;/strong&gt; (&lt;code&gt;N=20&lt;/code&gt; clients, &lt;code&gt;T=25&lt;/code&gt; rounds, &lt;code&gt;Dirichlet(0.5)&lt;/code&gt;, &lt;code&gt;9&lt;/code&gt; aggregators × &lt;code&gt;8&lt;/code&gt; attacks) and a &lt;strong&gt;2-layer tanh MLP DLG / iDLG gradient-inversion benchmark&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F18zozxgxs5tryqdulo7b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F18zozxgxs5tryqdulo7b.png" alt="Non-IID FL Resilience Heatmap" width="799" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8y4jre7y7ij2rl4fp7km.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8y4jre7y7ij2rl4fp7km.png" alt="DLG Privacy Utility Frontier" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Byzantine Resilience:&lt;/strong&gt; &lt;code&gt;FedAvg&lt;/code&gt; collapses to &lt;strong&gt;&lt;code&gt;6.5%&lt;/code&gt;&lt;/strong&gt; (Gaussian) and &lt;strong&gt;&lt;code&gt;37.5%&lt;/code&gt;&lt;/strong&gt; (40% Sign-Flip); &lt;code&gt;Multi-Krum&lt;/code&gt; collapses to &lt;strong&gt;&lt;code&gt;11.6%&lt;/code&gt;&lt;/strong&gt; (Gaussian). &lt;strong&gt;&lt;code&gt;EvoSec-TPU v2 (Champ)&lt;/code&gt;&lt;/strong&gt; holds &lt;strong&gt;&lt;code&gt;83.0%–83.2%&lt;/code&gt;&lt;/strong&gt; across Gaussian, Sign-Flip, Sybil, unseen ALIE, unseen Label-Flip, and 40% Sign-Flip!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DLG Privacy Frontier:&lt;/strong&gt; At &lt;code&gt;ε = 1.0&lt;/code&gt;, &lt;strong&gt;&lt;code&gt;Evo-PrivEdge v2 (Champ)&lt;/code&gt;&lt;/strong&gt; pushes attacker reconstruction MSE to &lt;strong&gt;&lt;code&gt;2.516&lt;/code&gt;&lt;/strong&gt; (well above the &lt;code&gt;1.85&lt;/code&gt; inversion-failure threshold) while keeping &lt;strong&gt;&lt;code&gt;0.959&lt;/code&gt;&lt;/strong&gt; gradient cosine utility (vs Uniform DP-SGD &lt;code&gt;MSE = 1.253&lt;/code&gt; at &lt;code&gt;cos = 0.499&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Live Gemma 4 E4B Co-Evolution on Colab &lt;code&gt;v6e-1&lt;/code&gt;:&lt;/strong&gt; In Lab 4 of our Colab notebook, we load open-weights &lt;strong&gt;&lt;code&gt;google/gemma-4-E4B-it&lt;/code&gt;&lt;/strong&gt; directly into TPU &lt;code&gt;v6e-1&lt;/code&gt;'s 32 GB HBM via Hugging Face Transformers v5 (&lt;code&gt;device_map="tpu"&lt;/code&gt;, &lt;code&gt;dtype=torch.bfloat16&lt;/code&gt;) to propose adaptive red-team attack parameters and stress-test &lt;code&gt;Evo Top-K (v1)&lt;/code&gt; vs &lt;code&gt;EvoSec-TPU v2 (Champ)&lt;/code&gt; in a closed co-evolution loop.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  7. Constructive Feedback for the TorchTPU Team (&lt;code&gt;#TorchTPUSprint&lt;/code&gt;)
&lt;/h2&gt;

&lt;p&gt;Building end-to-end on &lt;code&gt;torch-tpu==0.3.0&lt;/code&gt; was a blast—&lt;code&gt;torch.compile(backend="tpu")&lt;/code&gt; delivered &lt;strong&gt;&lt;code&gt;316.8×&lt;/code&gt;&lt;/strong&gt; over naive Multi-Krum and &lt;strong&gt;&lt;code&gt;13.6×–23.9×&lt;/code&gt;&lt;/strong&gt; over Strict Eager out of the box! Three small ergonomic improvements would make TorchTPU even smoother for security &amp;amp; scientific PyTorch developers:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Implement &lt;code&gt;aten::median&lt;/code&gt; natively on TPU (critical for robust statistics, MAD, and Byzantine FL defenses).&lt;/li&gt;
&lt;li&gt;Allow &lt;code&gt;@torch.tpu.pallas.jax_op&lt;/code&gt; to resolve type annotations cleanly when &lt;code&gt;from __future__ import annotations&lt;/code&gt; is active.&lt;/li&gt;
&lt;li&gt;Emit a clear warning (instead of a libtpu &lt;code&gt;periodicclosure.cc:33&lt;/code&gt; SIGABRT) if &lt;code&gt;jax.profiler.start_trace()&lt;/code&gt; is invoked while &lt;code&gt;torch.profiler.ProfilerActivity.TPU&lt;/code&gt; is active.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Try It Yourself
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;GitHub Repo:&lt;/strong&gt; &lt;a href="https://github.com/Unisvet/evosec-torchtpu" rel="noopener noreferrer"&gt;github.com/Unisvet/evosec-torchtpu&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;1-Click Colab (&lt;code&gt;v6e-1&lt;/code&gt; TPU):&lt;/strong&gt; &lt;a href="https://colab.research.google.com/github/Unisvet/evosec-torchtpu/blob/main/notebooks/EvoSec_TorchTPU_Sprint_2026.ipynb" rel="noopener noreferrer"&gt;Launch EvoSec_TorchTPU_Sprint_2026.ipynb&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Supported by the German Federal Ministry of Research, Technology and Space (BMFTR), Project AI-DISCO (Grant ID: 16ME1127), Chair of Wireless Systems, Brandenburg University of Technology (BTU) Cottbus-Senftenberg.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>torchtpusprint</category>
      <category>federatedlearning</category>
      <category>tpu</category>
      <category>security</category>
    </item>
  </channel>
</rss>
