Re review report · NVIDIA/hyperflare-inference #742

Raw Markdown for agents: https://autobot.eidonix.com/p/26661515-4237-4a7b-bf0f-d9628ed75f39.md

Recommendation: Changes Requested

Commit 66d6af3 cleanly resolved most of Round 1's feedback: max_sequence_pages: NonZeroU64 is now threaded through PlannedHostBudgets into NativeModel::prepare_offload (eliminating the duplicate lookup and model.rs None fallback), max_sequence_tokens == 0 is rejected in memory.rs, PrepareInputs::max_sequence_pages uses Option<NonZeroU64> with a single clamp in headroom_inner, and the tests and docs were tightened. However, one half of Round 1's Should Fix remains unfixed: helios/src/runtime_core/memory.rs:999 still calls context.div_ceil(contract.cache.page_tokens as u64) without guarding contract.cache.page_tokens == 0 (panicking on division by zero under default KvCacheLimit::Memory before PreparedContract::validate ever runs), and the new .ok_or_else(...) at :1000 is unreachable dead code. A 2-line non-zero check on contract.cache.page_tokens before div_ceil will make this ready to merge.

Merge Risk

Level: Low

Walkthrough

Pre-merge Checks

Blockers

None.

Should Fix

  1. Unfixed half of Round 1 Should Fix #1: div_ceil(contract.cache.page_tokens as u64) still panics on zero contract.cache.page_tokens, and the new NonZeroU64::new(...).ok_or_else(...) branch is dead code (helios/src/runtime_core/memory.rs:993-1000)
    • Verified behavior: In allocate_caches (memory.rs:884), memory.rs:896-899 validates self.server_config["page_tokens"] != 0, not contract.cache.page_tokens. contract is deserialized from self.server_config["model_contract"] at memory.rs:900-902 without calling PreparedContract::validate(), and NativeModel::load_agreeing runs allocate_caches (flare-cli/src/main.rs:323 -> model.rs:1038) before ModelConfig::from_server_config / PreparedContract::validate (helios/src/model/contract.rs:536), while protobuf::serving_contract (helios/src/runtime_core/protobuf.rs:75-89) does not validate contract.cache.page_tokens. Under the default KvCacheLimit::Memory mode, page_ceiling returns Ok(None) immediately at memory.rs:568-570 before its contract.cache.page_tokens == 0 check at :571. Consequently:
      1. If contract.cache.page_tokens == 0, line 999 executes context.div_ceil(0) unconditionally on every model load (even with offload disabled) and panics with attempt to divide by zero before NonZeroU64::new is called — regressing main, which returned Err(invalid(...)) via cache_geometry -> CacheGeometry::validate() (memory.rs:1024,1890).
      2. Because context > 0 is already enforced at memory.rs:995 and u64::div_ceil on a positive dividend with any positive divisor is always >= 1, .ok_or_else(|| invalid("model requires a positive prepared context ceiling"))? at memory.rs:1000 is unsatisfiable dead code.
    • Fix: Validate contract.cache.page_tokens as non-zero before calling div_ceil and replace the dead .ok_or_else with .expect(...):
      let logical_page_tokens = std::num::NonZeroU64::new(contract.cache.page_tokens as u64)
          .ok_or_else(|| invalid("model requires a positive cache page size"))?;
      let max_sequence_pages =
          std::num::NonZeroU64::new(context.div_ceil(logical_page_tokens.get()))
              .expect("positive context divided by positive page size is non-zero");
      

Subtract / Simplify

  1. Take NonZeroU64 (instead of Option<NonZeroU64>) in private NativeModel::prepare_offload (helios/src/runtime_core/model.rs:1052,1125,1172): prepare_offload is private (unsafe fn), its sole production call site passes Some(planned.max_sequence_pages), and only the two early-returning unit tests (model.rs:1562,1574) pass None. Keeping Option<NonZeroU64> only on PrepareInputs (for library callers) avoids redundant Option wrapping at the private Helios boundary.

Nits

Dropped on verification