Skip to content

perf(otfm): encode condition once, batch conditions in predict#309

Open
selmanozleyen wants to merge 1 commit into
theislab:mainfrom
selmanozleyen:perf/predict-encode-once-batched
Open

perf(otfm): encode condition once, batch conditions in predict#309
selmanozleyen wants to merge 1 commit into
theislab:mainfrom
selmanozleyen:perf/predict-encode-once-batched

Conversation

@selmanozleyen

Copy link
Copy Markdown
Collaborator

Split ConditionalVelocityField.call into encode_condition + velocity_from_embedding so the predict ODE integrates a precomputed embedding instead of re-encoding the condition on every step, and make OTFM.predict solve all conditions in one condition-batched vmap (no guidance) instead of a per-condition Python loop, concatenating ragged per-condition cells so no padding is needed.

Numerically identical to the previous per-condition/per-step path (max abs diff ~1e-6, floating point only); the guidance path is unchanged. Encoding once is ~1.2x with attention pooling; batching conditions is ~1.5x and compiles one kernel instead of recompiling per distinct source-cell count.

@selmanozleyen
selmanozleyen force-pushed the perf/predict-encode-once-batched branch from 3e27cfb to f532232 Compare July 14, 2026 13:51
Split ConditionalVelocityField.__call__ into encode_condition +
velocity_from_embedding so the predict ODE integrates a precomputed
embedding instead of re-encoding the condition on every step, and make
OTFM.predict solve all conditions in one condition-batched vmap (no
guidance) instead of a per-condition Python loop, concatenating ragged
per-condition cells so no padding is needed.

Numerically identical to the previous per-condition/per-step path
(max abs diff ~1e-6, floating point only); the guidance path is
unchanged. Encoding once is ~1.2x with attention pooling; batching
conditions is ~1.5x and compiles one kernel instead of recompiling per
distinct source-cell count.
@selmanozleyen
selmanozleyen force-pushed the perf/predict-encode-once-batched branch from 7fdef37 to d7fa03a Compare July 14, 2026 13:54
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