Skip to content

feat: --xla, XLA-compiled inference for .h5 and .scnm models - #65

Merged
uermel merged 2 commits into
v2.0from
uermel/xla-inference-v2
Oct 21, 2026
Merged

uermel merged 2 commits into
v2.0from
uermel/xla-inference-v2

Conversation

@uermel

@uermel uermel commented Oct 21, 2026

Copy link
Copy Markdown
Member

Port of the main-line --xla change and the easymode 1.2.6 bump to v2.0. The code is identical to main's.

Adds an opt-in --xla flag to copick inference easymode that runs each model's forward pass as one XLA-compiled function, tf.function(jit_compile=True). It is the option released upstream as easymode segment --xla in easymode 1.2.6 (mgflast/easymode#37) and ais segment --xla in ais-cryoet 1.2.40 (mgflast/Ais#16).

  • core/xla.py: XLAModel is called like the Keras model and hands every other attribute to the model, so the .h5 tiling and the .scnm inference use it unchanged. Each input shape compiles once and is logged. If a compiled call raises, the worker warns once and continues with the plain model.
  • InferenceSettings.xla, dispatch_easymode_inference(xla=...) and run_easymode_inference(xla=...) carry it to the workers.
  • CLI: --xla/--no-xla, off by default, because a missing or too old ptxas can abort TensorFlow outright.
  • Report: a top-level "xla", and per worker xla_fallbacks with feature and reason.
  • Supported easymode: 1.2.6, tag v1.2.6 (00ab903).
    • The tagged-easymode CI job and VALIDATION.md install it.
    • The .h5 functions this package uses are unchanged.
  • The .scnm port follows ais-cryoet 1.2.40.
    • Its slab stride keeps the half-depth default, and easymode does not override it.
    • Under XLA, a short last 2.5D batch is padded with zeros to the batch size, so one shape compiles.

Measured on the main line: three 10521 tomograms at TTA 4 on one L40S with TensorFlow 2.21.

  • Speed: microtubule .h5 went from 310 s to 107 s per tomogram, 2.9x. Actin .scnm slab went from 87 s to 67 s, 1.3x.
  • Masks: they matched plain inference to an IoU of 0.9998 or better, and no fallback occurred.

Tests:

  • 96 passed with easymode 1.2.6 installed the way the tagged-easymode job installs it.
  • The job's boundary check passes: version 1.2.6, commit 00ab903.

🤖 Generated with Claude Code

uermel and others added 2 commits October 19, 2026 21:13
`copick inference easymode --xla` runs each model's forward pass as one
XLA-compiled function. It is off by default. An `XLAModel` wrapper is
called like the Keras model and passes every other attribute through,
so easymode's tiling of an .h5 network and the .scnm inference use it
unchanged. Each worker compiles at the first call of each input shape
and logs the time. If a compiled call raises, the worker warns once
and continues with the plain model.

The report records `"xla"`, and each worker lists in `xla_fallbacks`
any model that gave up XLA, with the reason.

On three 10521 tomograms at TTA 4 on one L40S with TensorFlow 2.21:
the microtubule .h5 network went from 310 s to 107 s per tomogram,
2.9x, and the actin .scnm slab model from 87 s to 67 s, 1.3x. The
masks matched the plain model's to an IoU of 0.9998 or better.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
easymode 1.2.6 and ais-cryoet 1.2.40 release the --xla options this
package mirrors (mgflast/easymode#37, mgflast/Ais#16). The .h5 path
uses only _pad_volume, _segment_tomogram_instance and load_model, which
are unchanged, so the bump is the supported version and commit, the
tests and the docs.

The .scnm port follows ais-cryoet 1.2.40: its slab --stride keeps the
depth // 2 default, which easymode does not override, and under XLA a
short last 2.5D batch is padded with zeros to the batch size so the
compiled function keeps one input shape. The docs also drop the claim
that easymode is not on PyPI, and name its new metadata pins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@uermel
uermel merged commit 75ef67b into v2.0 Oct 21, 2026
8 checks passed
uermel pushed a commit that referenced this pull request Oct 21, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.0.0-alpha.4](copick-easymode-v2.0.0-alpha.3...copick-easymode-v2.0.0-alpha.4)
(2026-10-21)


### Features

* --xla, XLA-compiled inference for .h5 and .scnm models
([#65](#65))
([75ef67b](75ef67b))

---
Merging this PR will create a new alpha prerelease for copick-easymode.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

1 participant