Repository navigation
[AINode] Build the result TsBlock with numpy instead of appending one value at a time - #19251
Open
kotselidis wants to merge 2 commits into
Open
kotselidis wants to merge 2 commits into
kotselidis wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Higher-rank tensors are accepted without rank validation, allowing the TsBlock header’s declared position count to differ from the number of serialized values.
1 open issue
What changed in this PR
This PR speeds up AINode inference-result serialization by replacing repeated byte appends with bulk NumPy conversion, targeting quadratic conversion costs for large outputs.
Changes:
- Builds time and value columns in bulk and joins serialized parts once.
- Adds byte-equivalence tests across tensor shapes and types, plus a large-output performance check.
- Removes the unused
structimport and corrects the conversion comment.
| File | Description |
|---|---|
iotdb-core/ainode/tests/test_serde.py |
Adds reference-based serialization tests and a performance regression check. |
iotdb-core/ainode/iotdb/ainode/core/util/serde.py |
Uses bulk big-endian NumPy serialization instead of per-value appends. |
Review effort: Balanced
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
RkGrit
self-requested a review
November 13, 2026 16:35
Contributor
|
LGTM~ |
RkGrit
approved these changes
Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Description
The problem
convert_tensor_to_tsblockiniotdb/ainode/core/util/serde.pybuilds the TsBlock that AINode returns to the DataNode by appending to abytesobject one value at a time (binary += value.tobytes()). Each append copies the whole object, so the conversion is quadratic in the number of output values.It matters whenever a model returns a value per input point, for example a custom model that scores every point of a series through
CALL INFERENCE. Measured in AINode's own environment (2.0.11, Python 3.11) for a1 x nfloat64 tensor:End to end, a
CALL INFERENCEthat returns 100,000 per-point scores from a custom PyTorch model on a GPU took 10.1 s, of which 9.7 s was this conversion and 0.33 s the model. Results of a few hundred thousand points take minutes and run intodn_connection_timeout_ms, and the DataNode then retries the call.The change
The function now takes the tensor's columns as a numpy array and builds the same layout from a list of parts joined once:
bytes(8 * position_count)block, which is what the previous loop wrote (two big-endian int32 zeros per row);ndarray.tobytes().The output is byte-for-byte the same as before. The new
tests/test_serde.pykeeps the previous implementation as a reference and compares the two on scalars, 1-D and 2-D tensors, float32, float64, int32, int64 and bool, NaN, infinities and -0.0, a non-contiguous tensor, and a 2 x 20,000 float64 tensor.After the change, the conversion takes 2 ms for 100,000 values and 5.5 ms for 1,000,000. The
CALL INFERENCEabove takes 0.34 s instead of 10.1 s.structis no longer used and its import is removed;pandasis still used by the type helpers.Verification
Run with AINode 2.0.11's environment (PyTorch 2.9.1), with Black 25.1.0 and isort 6.0.1. I have not run it on the PyTorch 2.14 environment that master's
pyproject.tomlnow pins, nor run the AINode cluster integration tests.This PR has: