-
Notifications
You must be signed in to change notification settings - Fork 344
fix(embed): fail the run when embed rows arrive with no embedding #2551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rhdong
wants to merge
4
commits into
NVIDIA:main
Choose a base branch
from
rhdong:fix/incomplete-index-silent-success
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
128e936
fix(embed): fail the run when embed rows arrive with no embedding
rhdong b7275b9
test(embed): consolidate guard tests into the existing suites
rhdong 698de56
fix(embed): align guard scope and cardinality handling
rhdong 5998966
test(embed): exercise loss guards through public paths
rhdong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. | ||
| # All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Embed failures that mean rows were lost. | ||
|
|
||
| Kept in their own module, with no third-party imports, so the local embedders | ||
| and the embed runtime can both import them on the endpoint-only path. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from typing import Sequence | ||
|
|
||
| from nemo_retriever.models.nim.error_reporter import report_error | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class LocalEmbedderReturnedNothingError(RuntimeError): | ||
| """An in-process embedder returned no vectors for a non-empty batch.""" | ||
|
|
||
|
|
||
| class LocalEmbedderRowsLostError(RuntimeError): | ||
| """An in-process embedder produced no vector for some rows of a batch. | ||
|
|
||
| Raised by :func:`report_lost_rows`. ``models/inference/runtime.py`` | ||
| classifies both errors in this module as fatal by name. | ||
|
|
||
| Args: | ||
| lost: Number of rows with no vector. | ||
| total: Size of the batch. | ||
| embedder: Class name of the embedder that lost them. | ||
| """ | ||
|
|
||
| def __init__(self, *, lost: int, total: int, embedder: str) -> None: | ||
| self.lost = int(lost) | ||
| self.total = int(total) | ||
| self.embedder = str(embedder) | ||
| super().__init__( | ||
| f"{embedder} returned no vector for {lost} of {total} row(s) in this batch. " | ||
| "Continuing would pad or drop those rows, hide the loss, and allow an invalid or " | ||
| "incomplete index to be published. This normally means the in-process engine failed " | ||
| "for the batch - check the embed actor logs for engine initialization or out-of-memory " | ||
| "errors." | ||
| ) | ||
|
|
||
|
|
||
| def _has_no_vector(vector: object) -> bool: | ||
| """Return whether ``vector`` is empty or absent. | ||
|
|
||
| Explicit rather than truthy: ``not vector`` raises on a multi-element numpy | ||
| array. | ||
| """ | ||
| if vector is None: | ||
| return True | ||
| if hasattr(vector, "__len__"): | ||
| return len(vector) == 0 | ||
| return False | ||
|
|
||
|
|
||
| def report_lost_rows(vectors: Sequence[Sequence[float]], *, embedder: str) -> int: | ||
| """Raise :class:`LocalEmbedderRowsLostError` if any row came back empty. | ||
|
|
||
| Returns ``0`` when nothing was lost; never returns a non-zero count. | ||
|
|
||
| Called from the local embedders' ``_finalize_vectors`` before they discard | ||
| empty placeholders. Raising before padding is required because a padded row | ||
| has the right width, so ``has_embedding`` would report ``True`` for a row | ||
| carrying nothing. | ||
| """ | ||
| lost = sum(1 for vector in vectors if _has_no_vector(vector)) | ||
| if not lost: | ||
| return 0 | ||
|
|
||
| exc = LocalEmbedderRowsLostError(lost=lost, total=len(vectors), embedder=embedder) | ||
| logger.error("%s", exc) | ||
| report_error("embed", exc) | ||
| raise exc |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.