OptiRS TPU
TPU-style coordination, pod management, and an XLA-shaped compilation pipeline for large-scale distributed optimization in the OptiRS machine learning optimization library.
Overview
optirs-tpu implements the coordination and compilation logic a TPU pod optimizer needs
— device/pod topology, barrier synchronization, fault detection and checkpointing, and an
XLA-style graph compiler (shape inference, constant folding, common-subexpression
elimination, dead-code elimination, kernel fusion, memory planning) — as real, tested, pure
Rust algorithms running on a CPU reference executor.
There is no Google Cloud / vendor TPU runtime linked into this crate. That runtime is
proprietary and cannot be shipped as pure Rust, so this crate does not provision TPU pods,
authenticate against GCP, or execute on physical TPU silicon. Where a capability genuinely
needs that runtime (e.g. migrating a running workload between devices), the corresponding
function returns a descriptive Err rather than a fabricated success. See the crate-level
doc comment (cargo doc -p optirs-tpu --open) for the current per-module status.
What's real
TPUOptimizerwraps anyoptirs_core::Optimizer(and implements that trait itself), driving it through a real compile → execute → profile pipeline.- XLA-shaped compiler (
xlamodule): computation-graph construction with real producer/consumer dependency tracking, dead-code elimination (with a fail-safe against deleting a graph whose outputs were never declared), constant folding, common sub-expression elimination, kernel-fusion legality checks, a real allocator with free/coalescing (not bump-only), and shape inference for reshape, convolution, dot, and broadcast. coordination::PodCoordinator: device and pairwise-channel topology, barrier synchronization, load balancing, and fault detection over real, observable in-process state.fault_tolerance: checkpoints are serialized to disk with a SHA-256 integrity hash and verified on restore; rollback and replication reuse that same verified path.synchronization: barriers with a correctly-signaled condvar predicate, plus ring all-reduce / broadcast / reduce-scatter collectives.pod_coordination::TPUPodCoordinator<T>: delegates every operation to the realcoordination::PodCoordinatorabove (translating between their two independently designed config schemas); it used to hold only its config with no other methods.pod_coordination::synchronization::clocks::protocols::NtpSynchronizer: real RFC 5905 four-timestamp round-trip clock-offset estimation, rejecting a physically inconsistent exchange withErrrather than fabricating an offset.
What's not implemented
- Execution on real TPU hardware (needs a vendor runtime this crate does not have).
- Cross-device workload migration (
FaultToleranceManager::migrate_workloadreturnsErrby design rather than fabricate a live migration). - Cloud provisioning, billing/spot-bidding, and multi-region orchestration are out of scope for this crate; it coordinates a pod you already have, it does not create one.
xla::backend::profiling_integration's memory export reflects real activity only once a program has actually run:TPUBackend::run_one_attemptrecords every device-memory reservation and release it makes into that same profiler (ProfilingIntegration::record_memory_allocation/record_memory_release), including a peak-occupancy snapshot taken while the reservation is still held. Compile a program without executing it and the memory export is honestly empty — there is nothing to report yet — while the counter/trace exports already carry real recorded compile-step timings regardless.- Some deeper
pod_coordinationsubmodules are still mixed-maturity scaffolding — check the module's own doc comments.
Installation
[]
= "0.3.2"
= "0.3.2"
Usage
use SGD;
use ;
TPUOptimizer also implements optirs_core::Optimizer, so it can be used anywhere generic
code expects one:
Pod coordination
use ;
Checkpointing
fault_tolerance::FaultToleranceManager::create_checkpoint serializes real coordination
state to disk under the configured storage path and records a SHA-256 hash;
restore_checkpoint re-verifies that hash before applying anything, so a corrupted or
truncated checkpoint fails loudly instead of silently "succeeding".
Architecture
Built on SciRS2 abstractions:
- Numeric:
scirs2_core::ndarray,scirs2_core::numeric::Float - Errors:
scirs2_core::error::CoreError, re-exported here asoptirs_tpu::error::OptimError
Module map:
coordination— pod/device topology, barriers, load balancing, fault detectionsynchronization— condvar barriers and ring collectivesfault_tolerance— checkpoint/restore, recovery strategiesmonitoring— health checks and performance reports over live metric historytpu_backend— device management and the CPU reference executorxla— the graph-capture / shape-inference / optimization / scheduling pipelinepod_coordination— larger-scale pod topology and clock-synchronization scaffolding (mixed maturity; consult individual module docs)
Development Guidelines
snake_casefor variables and functions,PascalCasefor types,SCREAMING_SNAKE_CASEfor constants, per RFC 430.- No fabricated success values or hardcoded placeholder outputs. Where a capability
genuinely requires hardware or a runtime this crate does not have, return a descriptive
Errrather than simulate one. - Before submitting:
cargo fmt,cargo clippy --all-features,cargo test --all-features.
Contributing
OptiRS follows the Cool Japan organization's development standards. See the main OptiRS repository for contribution guidelines.
License
This project is licensed under the Apache License, Version 2.0.