Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
fix(server): send float16 multivectors to the sidecar as bytes (#416)
Filip Makraduli7ee9f75ef54a
diff --git a/packages/sie_server/src/sie_server/queue_executor.py b/packages/sie_server/src/sie_server/queue_executor.pyindex 5d0963e8f..58f25caaf 100644--- a/packages/sie_server/src/sie_server/queue_executor.py+++ b/packages/sie_server/src/sie_server/queue_executor.py@@ -362,9 +362,18 @@ def _maybe_multivector_raw_output(formatted: dict[str, Any],config: Any,output_types: list[str],+ *,+ f16_bytes: bool = False,) -> RawOutput | None:"""Multivector-only fast path for the Rust output shaper.+ With ``f16_bytes`` (the sidecar declares it takes float16 byte buffers) a+ float16 matrix travels as its little-endian bytes in ``values_f16``: 2 bytes+ a value, where a list of Python floats packs as 9-byte msgpack doubles.+ Wide multivector models need it to stay under the IPC response cap: one+ 8,192-token document of a 2,048-dim model is 16.8M values, 144 MiB as+ doubles against 32 MiB as float16.+Mirrors the invariants of the ``multivector`` branch of``_wrap_encode_output``:@@ -409,6 +418,17 @@ def _maybe_multivector_raw_output(else:token_dims = int(arr.shape[1])+ if f16_bytes and arr.dtype == np.float16:+ return RawOutput(+ multivector=MultivectorOutput(+ values=[],+ num_tokens=num_tokens,+ token_dims=token_dims,+ dtype="float16",+ values_f16=np.ascontiguousarray(arr, dtype="<f2").tobytes(),+ ),+ )+# Values must be contiguous in C order so ``.tobytes()`` (and the# Rust ``values.to_le_bytes()`` equivalent) agree. ``tolist()``# on a 2-D ndarray returns a nested list; ``ravel()`` flattens@@ -1088,6 +1108,7 @@ class QueueExecutor:request_options=group[0].options or {},outcomes=outcomes,isolation=isolation,+ f16_bytes=req.accepts_batched_f16_multivectors,)return BatchOutcome(outcomes=[outcomes[bi.work_item_id] for bi in items])@@ -1105,6 +1126,7 @@ class QueueExecutor:outcomes: dict[str, ItemOutcome],isolation: _IsolationBudget,depth: int = 0,+ f16_bytes: bool = False,) -> None:"""Run one encode sub-group and record its per-item outcomes.@@ -1112,7 +1134,8 @@ class QueueExecutor:``InvalidInputError`` can be isolated by re-running narrower groups —see :meth:`_isolate_encode_invalid_input`. ``isolation`` is the batch'sshared re-run budget and ``depth`` the current bisection depth, both- carried only for that path.+ carried only for that path. ``f16_bytes``: the sidecar takes float16+ multivectors as byte buffers (see :func:`_maybe_multivector_raw_output`)."""# Validate each item against the typed Item contract at the seam# (parity with the HTTP path). A per-item decode failure is isolated@@ -1253,6 +1276,7 @@ class QueueExecutor:formatted_outputs[idx],config,response_output_types,+ f16_bytes=f16_bytes,)if raw_output is None:output = _wrap_encode_output(formatted_outputs[idx], config)@@ -1304,6 +1328,7 @@ class QueueExecutor:error=e,isolation=isolation,depth=depth,+ f16_bytes=f16_bytes,)except Exception as e: # noqa: BLE001logger.warning("Encode sub-batch failed for model %s: %s", model_id, e)@@ -1324,6 +1349,7 @@ class QueueExecutor:error: InvalidInputError,isolation: _IsolationBudget,depth: int,+ f16_bytes: bool = False,) -> None:"""Fail only the request that supplied the malformed input.@@ -1410,6 +1436,7 @@ class QueueExecutor:outcomes=outcomes,isolation=isolation,depth=depth + 1,+ f16_bytes=f16_bytes,)# -- Score -------------------------------------------------------------diff --git a/packages/sie_server/tests/test_queue_executor_stage1d.py b/packages/sie_server/tests/test_queue_executor_stage1d.pyindex 14d76dc17..a2bb0137f 100644--- a/packages/sie_server/tests/test_queue_executor_stage1d.py+++ b/packages/sie_server/tests/test_queue_executor_stage1d.py@@ -25,7 +25,9 @@ import timefrom pathlib import Pathfrom unittest.mock import AsyncMock, MagicMock, patch+import msgpackimport msgpack_numpy+import msgspecimport numpy as npimport pytestfrom sie_server.core.inference_output import ScoreOutput@@ -341,6 +343,52 @@ class TestMultivectorFastPathGate:assert raw.multivector.token_dims == 4assert raw.multivector.dtype == "float16"+ def test_float16_travels_as_bytes_when_the_sidecar_takes_them(self) -> None:+ arr = np.arange(12, dtype=np.float16).reshape(3, 4)+ raw = _maybe_multivector_raw_output({"multivector": arr}, self._config(), ["multivector"], f16_bytes=True)+ assert raw is not None+ assert raw.multivector is not None+ mv = raw.multivector+ assert (mv.num_tokens, mv.token_dims, mv.dtype) == (3, 4, "float16")+ assert mv.values == []+ assert mv.values_f16 == arr.astype("<f2").tobytes()++ def test_float16_stays_a_list_without_the_sidecar_flag(self) -> None:+ arr = np.arange(12, dtype=np.float16).reshape(3, 4)+ raw = _maybe_multivector_raw_output({"multivector": arr}, self._config(), ["multivector"])+ assert raw is not None+ assert raw.multivector is not None+ assert raw.multivector.values == arr.ravel().tolist()+ assert raw.multivector.values_f16 == b""++ def test_float32_stays_a_list_even_when_bytes_are_accepted(self) -> None:+ arr = np.arange(12, dtype=np.float32).reshape(3, 4)+ raw = _maybe_multivector_raw_output({"multivector": arr}, self._config(), ["multivector"], f16_bytes=True)+ assert raw is not None+ assert raw.multivector is not None+ assert raw.multivector.values == arr.ravel().tolist()+ assert raw.multivector.values_f16 == b""++ def test_float16_bytes_keep_the_ipc_response_small(self) -> None:+ # 2 bytes a value on the wire instead of 9 (a msgpack double per Python float).+ arr = np.ones((512, 2048), dtype=np.float16)+ packed = {+ flag: len(+ msgpack.packb(+ msgspec.to_builtins(+ _maybe_multivector_raw_output(+ {"multivector": arr}, self._config(mv_dim=2048), ["multivector"], f16_bytes=flag+ ),+ builtin_types=(bytes, memoryview),+ ),+ use_bin_type=True,+ )+ )+ for flag in (False, True)+ }+ assert packed[True] < 2.01 * arr.size+ assert packed[False] > 8.9 * arr.size+def test_bit_packed_binary_falls_back(self) -> None:# ``shape[1] < mv_dim`` signals binary multivector packed into# bytes; framing in Rust isn't supported yet, must fall back.@@ -469,6 +517,29 @@ class TestProcessEncodeBatchSparseMV:assert o.raw_output.multivector is not Noneassert o.raw_output.multivector.dtype == "float16"+ @pytest.mark.asyncio+ async def test_float16_multivector_travels_as_bytes_when_the_sidecar_accepts_them(self) -> None:+ reg = self._mv_registry()+ ex = QueueExecutor(reg)++ arr = np.arange(8, dtype=np.float16).reshape(2, 4)+ with patch(+ "sie_server.core.encode_pipeline.EncodePipeline.run_encode",+ new_callable=AsyncMock,+ return_value=([{"multivector": arr}], RequestTiming()),+ ):+ outcome = await ex.process_encode_batch(+ ProcessEncodeBatchRequest(+ model_id=MODEL_ID,+ items=[_encode_item(output_types=["multivector"])],+ accepts_batched_f16_multivectors=True,+ ),+ )++ mv = outcome.outcomes[0].raw_output.multivector+ assert mv.values == []+ assert mv.values_f16 == arr.astype("<f2").tobytes()+# -----------------------------------------------------------------------------# Score legacy-path verification — the unsorted/sorted equivalence