diff --git a/CHANGELOG.md b/CHANGELOG.md index 45392a4b7..4716abd3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -148,6 +148,14 @@ The public API snapshot records this version update; publication remains pending and `candidates=` instead. 1.0.0 built the request, and the endpoint refused it. +### Removed + +- The client no longer enforces its own copies of the endpoint's limits, so a deployment that raises them is not held back: the 10,000 relational context rows (`num_context_samples` may be larger), the 10,000 predict rows per call (`rows_per_call` may be larger; 10,000 stays the default batch), the tabular refusal past 10,000 context rows (`materialize()` still samples to 10,000 by default, with a warning), the 30 MiB request body, the 15-table cap, and the 100,000-entity and 100-call guards on `materialize()`. + The endpoint refuses what it does not take. + Sampling still supports at most six hops, including explicit neighbor-list depth. + The Databricks gateway's 16 MB check, `MOST_PARTS`, `top_k` of at most 20 and the 64 MiB response cap stay. + The contract is version 74. + ### Fixed - Explicit empty outputs remain invalid with `EXPLAIN`; unsupported local-runtime outputs are refused before model weights load. diff --git a/contract/expected/README.md b/contract/expected/README.md index 46dff694c..cd980940c 100644 --- a/contract/expected/README.md +++ b/contract/expected/README.md @@ -29,6 +29,12 @@ Their differences from DuckDB follow the fixture loader's explicit mappings in ` | SQLite / Postgres | Malformed text-time values are refused; the US-date fixture completes under these backends' existing read behavior | | Postgres | NaN-key fixtures refuse at materialize; a negative neighbor bound retains the existing `PROVIDER_ERROR` outcome | +`sample.num-hops.seven` and `sample.num-neighbors.seven-hops` refuse at materialize with `UNSUPPORTED_REQUEST`: sampling supports at most six hops. +The `multicall.body-30mib` cases reach predict on every backend: the client holds a call to no size of its own. +`multicall.entities.100001` and `multicall.calls.101` are gathered: the client sets no most on the entities or the calls of one `materialize()`. +`rank.entities-by-candidates.over` is refused at materialize only for the entities that name no user, as `rank.entities-by-candidates.at` is, since the client sets no entity ceiling over a ranking. +These outcomes were recorded from the runner's observations (`run_python.py`, then `check_observations.py --expect`) on DuckDB and SQLite; the Postgres entries take the same outcomes, as no Postgres server was available. + These expectations describe the declared fixture mappings; they do not claim that every backend supports identical physical types. `explain.two-entities` now succeeds on all three backends: The client supports explanations for multiple prediction rows. `contract/tests/test_query_options.py::test_each_explained_entity_retains_its_own_raw_response` independently checks both rows' distinct explanation values, the request batch size and the public success outcome. diff --git a/contract/expected/duckdb-python.json b/contract/expected/duckdb-python.json index 6f17223a2..3c3965cb2 100644 --- a/contract/expected/duckdb-python.json +++ b/contract/expected/duckdb-python.json @@ -108,13 +108,13 @@ "metadata.items": {"code": null, "error": null, "result": "success", "stage": "predict"}, "metadata.items-across-calls": {"code": null, "error": null, "result": "success", "stage": "predict"}, "metadata.items-explained": {"code": null, "error": null, "result": "success", "stage": "predict"}, - "multicall.body-30mib.one-row": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, - "multicall.body-30mib.several-rows": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "multicall.body-30mib.one-row": {"code": null, "error": null, "result": "success", "stage": "predict"}, + "multicall.body-30mib.several-rows": {"code": null, "error": null, "result": "success", "stage": "predict"}, "multicall.calls.100": {"code": null, "error": null, "result": "success", "stage": "predict"}, - "multicall.calls.101": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "multicall.calls.101": {"code": null, "error": null, "result": "success", "stage": "predict"}, "multicall.entities-per-call.10001": {"code": null, "error": null, "result": "success", "stage": "predict"}, "multicall.entities.100000": {"code": null, "error": null, "result": "success", "stage": "materialize"}, - "multicall.entities.100001": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "multicall.entities.100001": {"code": null, "error": null, "result": "success", "stage": "materialize"}, "multicall.fail-call-0": {"code": null, "error": "NimRequestError", "result": "refusal", "stage": "predict"}, "multicall.fail-call-2": {"code": null, "error": "NimRequestError", "result": "refusal", "stage": "predict"}, "multicall.forecast.batched": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, @@ -160,7 +160,7 @@ "rank.candidates-not-a-ranking": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.decimal-key": {"code": null, "error": null, "result": "success", "stage": "predict"}, "rank.entities-by-candidates.at": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, - "rank.entities-by-candidates.over": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "rank.entities-by-candidates.over": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.most-parts": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.no-candidates": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.odd-column": {"code": null, "error": null, "result": "success", "stage": "predict"}, diff --git a/contract/expected/postgres-python.json b/contract/expected/postgres-python.json index 31f136d65..cac91a95e 100644 --- a/contract/expected/postgres-python.json +++ b/contract/expected/postgres-python.json @@ -108,13 +108,13 @@ "metadata.items-across-calls@postgres": {"code": null, "error": null, "result": "success", "stage": "predict"}, "metadata.items-explained@postgres": {"code": null, "error": null, "result": "success", "stage": "predict"}, "metadata.items@postgres": {"code": null, "error": null, "result": "success", "stage": "predict"}, - "multicall.body-30mib.one-row@postgres": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, - "multicall.body-30mib.several-rows@postgres": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "multicall.body-30mib.one-row@postgres": {"code": null, "error": null, "result": "success", "stage": "predict"}, + "multicall.body-30mib.several-rows@postgres": {"code": null, "error": null, "result": "success", "stage": "predict"}, "multicall.calls.100@postgres": {"code": null, "error": null, "result": "success", "stage": "predict"}, - "multicall.calls.101@postgres": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "multicall.calls.101@postgres": {"code": null, "error": null, "result": "success", "stage": "predict"}, "multicall.entities-per-call.10001@postgres": {"code": null, "error": null, "result": "success", "stage": "predict"}, "multicall.entities.100000@postgres": {"code": null, "error": null, "result": "success", "stage": "materialize"}, - "multicall.entities.100001@postgres": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "multicall.entities.100001@postgres": {"code": null, "error": null, "result": "success", "stage": "materialize"}, "multicall.fail-call-0@postgres": {"code": null, "error": "NimRequestError", "result": "refusal", "stage": "predict"}, "multicall.fail-call-2@postgres": {"code": null, "error": "NimRequestError", "result": "refusal", "stage": "predict"}, "multicall.forecast.batched@postgres": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, @@ -160,7 +160,7 @@ "rank.candidates-not-a-ranking@postgres": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.decimal-key@postgres": {"code": null, "error": null, "result": "success", "stage": "predict"}, "rank.entities-by-candidates.at@postgres": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, - "rank.entities-by-candidates.over@postgres": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "rank.entities-by-candidates.over@postgres": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.most-parts@postgres": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.no-candidates@postgres": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.odd-column@postgres": {"code": null, "error": null, "result": "success", "stage": "predict"}, diff --git a/contract/expected/sqlite-python.json b/contract/expected/sqlite-python.json index a1efac620..8a511b92a 100644 --- a/contract/expected/sqlite-python.json +++ b/contract/expected/sqlite-python.json @@ -108,13 +108,13 @@ "metadata.items-across-calls@sqlite": {"code": null, "error": null, "result": "success", "stage": "predict"}, "metadata.items-explained@sqlite": {"code": null, "error": null, "result": "success", "stage": "predict"}, "metadata.items@sqlite": {"code": null, "error": null, "result": "success", "stage": "predict"}, - "multicall.body-30mib.one-row@sqlite": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, - "multicall.body-30mib.several-rows@sqlite": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "multicall.body-30mib.one-row@sqlite": {"code": null, "error": null, "result": "success", "stage": "predict"}, + "multicall.body-30mib.several-rows@sqlite": {"code": null, "error": null, "result": "success", "stage": "predict"}, "multicall.calls.100@sqlite": {"code": null, "error": null, "result": "success", "stage": "predict"}, - "multicall.calls.101@sqlite": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "multicall.calls.101@sqlite": {"code": null, "error": null, "result": "success", "stage": "predict"}, "multicall.entities-per-call.10001@sqlite": {"code": null, "error": null, "result": "success", "stage": "predict"}, "multicall.entities.100000@sqlite": {"code": null, "error": null, "result": "success", "stage": "materialize"}, - "multicall.entities.100001@sqlite": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "multicall.entities.100001@sqlite": {"code": null, "error": null, "result": "success", "stage": "materialize"}, "multicall.fail-call-0@sqlite": {"code": null, "error": "NimRequestError", "result": "refusal", "stage": "predict"}, "multicall.fail-call-2@sqlite": {"code": null, "error": "NimRequestError", "result": "refusal", "stage": "predict"}, "multicall.forecast.batched@sqlite": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, @@ -160,7 +160,7 @@ "rank.candidates-not-a-ranking@sqlite": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.decimal-key@sqlite": {"code": null, "error": null, "result": "success", "stage": "predict"}, "rank.entities-by-candidates.at@sqlite": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, - "rank.entities-by-candidates.over@sqlite": {"code": "UNSUPPORTED_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, + "rank.entities-by-candidates.over@sqlite": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.most-parts@sqlite": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.no-candidates@sqlite": {"code": "INVALID_REQUEST", "error": "StructuredDataError", "result": "refusal", "stage": "materialize"}, "rank.odd-column@sqlite": {"code": null, "error": null, "result": "success", "stage": "predict"}, diff --git a/contract/support/error_wording_scenarios.py b/contract/support/error_wording_scenarios.py index adffa05f5..453d64124 100644 --- a/contract/support/error_wording_scenarios.py +++ b/contract/support/error_wording_scenarios.py @@ -65,12 +65,10 @@ 'sample.max-pq-iterations.zero', 'sample.num-hops.bool', 'sample.num-hops.fraction', - 'sample.num-hops.seven', 'sample.num-hops.text', 'sample.num-hops.zero', 'sample.num-neighbors.empty', 'sample.num-neighbors.number', - 'sample.num-neighbors.seven-hops', 'sample.seed.negative', 'shape.star.customers', 'target.filter.sum', diff --git a/contract/tests/test_prediction_batching.py b/contract/tests/test_prediction_batching.py index 822d6beeb..9af000863 100644 --- a/contract/tests/test_prediction_batching.py +++ b/contract/tests/test_prediction_batching.py @@ -65,26 +65,10 @@ #: reference gives (the ceilings' counts, the 30 MiB body's mark). REFUSED = { **{case: ('INVALID_REQUEST', {}) for case in INVALID}, - 'multicall.entities.100001': ( - 'UNSUPPORTED_REQUEST', - {'entities': 100_001, 'gathered_times': 1, 'total': 100_001}, - ), - 'multicall.calls.101': ( - 'UNSUPPORTED_REQUEST', - {'entities': 101, 'calls': 101, 'rows_per_call': 1}, - ), 'multicall.forecast.batched': ( 'UNSUPPORTED_REQUEST', {'entities': 8, 'rows_per_call': 3}, ), - 'multicall.body-30mib.one-row': ( - 'INVALID_REQUEST', - {'batch_too_large_to_send': True}, - ), - 'multicall.body-30mib.several-rows': ( - 'INVALID_REQUEST', - {'batch_too_large_to_send': True}, - ), } #: The failed calls, by case: the call failed, and what the error carries #: of the calls before it (``calls_answered`` and ``rows_answered``, or a @@ -102,6 +86,14 @@ 'the call: materialize(rows_per_call=N) below the 3 this one holds' ), } +#: The cases this client departs from the reference on, on purpose: it holds a +#: request to no size of its own (no entity, call or body ceiling), so each is +#: gathered where the reference refused it at materialize. +DEPARTED = ( + 'multicall.entities.100001', + 'multicall.calls.101', + *BODY, +) CASE_IDS = ( 'multicall.rows-per-call-3', 'multicall.fail-call-2', @@ -404,6 +396,8 @@ def test_current_client_batches_without_label_or_entity_leakage( database = case_key.partition('@')[2] or 'duckdb' if database == 'postgres' and not _server(): pytest.skip('Postgres test DSN is not configured') + if case_key.split('@')[0] in DEPARTED: + pytest.skip('a departure from the reference, checked on its own') def check() -> None: run = core_run(database) @@ -511,6 +505,8 @@ def test_batching_preserves_rows_limits_and_partial_answers( case_id, _, database = case_key.partition('@') if database == 'postgres' and not _server(): pytest.skip('Postgres test DSN is not configured') + if case_id in DEPARTED: + pytest.skip('a departure from the reference, checked on its own') case, _ = cases()[case_id] got = core_carried(case_key) assert same_outcome(_expected(case), _outcome(got)) @@ -584,3 +580,13 @@ def test_transport_errors_keep_completed_answers(case_key: str) -> None: steps = [1] if 'parts_answered' in RAISED[case_id] else None assert_scored_rows(got['answered'], indices, steps) assert got['result'] is None + + +@pytest.mark.parametrize('case_id', DEPARTED) +def test_python_core_gathers_and_predicts_what_the_reference_refused( + case_id: str, +) -> None: + r"""The client sets no most on the entities, the calls or the body: each + case is answered.""" + got = core_carried(case_id) + assert got['outcome']['result'] == 'success', got['outcome'] diff --git a/contract/tests/test_public_error_messages.py b/contract/tests/test_public_error_messages.py index c363d4752..280503348 100644 --- a/contract/tests/test_public_error_messages.py +++ b/contract/tests/test_public_error_messages.py @@ -110,12 +110,10 @@ def runner() -> ModuleType: 'sample.max-pq-iterations.zero': ['max_pq_iterations', '0'], 'sample.num-hops.bool': ['num_hops', 'True'], 'sample.num-hops.fraction': ['num_hops', '1.5'], - 'sample.num-hops.seven': ['7 hops', '6'], 'sample.num-hops.text': ['num_hops', "'2'"], 'sample.num-hops.zero': ['num_hops', 'num_neighbors=[8, 8]'], 'sample.num-neighbors.empty': ['num_neighbors', 'no hop'], 'sample.num-neighbors.number': ['num_neighbors', 'sequence'], - 'sample.num-neighbors.seven-hops': ['7 hops', '6'], 'sample.seed.negative': ['random_seed', '-1'], 'wording.rank-text-candidate': ['buys.item_id', "'1'"], 'wording.float32-classification': ['non-finite', 'inf'], diff --git a/contract/tests/test_ranking.py b/contract/tests/test_ranking.py index 1edcb194a..86754e6f5 100644 --- a/contract/tests/test_ranking.py +++ b/contract/tests/test_ranking.py @@ -50,14 +50,19 @@ 'holds one class left out, unscored, before any call', 'rank.all-unscored': 'no candidate left to rank, refused before any call', 'rank.entities-by-candidates.over': 'the entities gathered once ' - 'per candidate past the 100,000 one materialize holds (501 by 200), ' - 'refused before anything is read', + "per candidate past the reference's 100,000 (501 by 200), which it " + 'refused; this client sets no such ceiling (DEPARTED)', 'rank.entities-by-candidates.at': 'the same at exactly 100,000 ' '(500 by 200), not refused by that ceiling', 'forecast.top-k': "the forecast's top_k refusal in the core", 'forecast.most-parts': "the forecast's MOST_PARTS refusal in the core", } CASE_IDS = tuple(CASES) +#: The cases this client departs from the reference on, on purpose: it sets +#: no ceiling on the entities a ranking gathers across its candidates, so the +#: reference's refusal past 100,000 is gathered, and refused only for the +#: entities that name no user, as at the ceiling. +DEPARTED = ('rank.entities-by-candidates.over',) #: The sentence the reference adds to a part's refusal. PART = 'This is the question asked for candidate ' @@ -217,12 +222,9 @@ def _outcome(line: dict[str, Any]) -> tuple[Any, ...]: 'rank.candidates-not-a-ranking': 'does not rank anything', 'rank.most-parts': '201 candidates means 201 calls', 'rank.batched': 'A part is not batched', - 'rank.entities-by-candidates.over': ( - '501 entities gathered 200 times over, 100,200 in all, is past the ' - '100,000' - ), - # At the ceiling the call is gathered, and refused only for the - # entities 8 to 499, which name no user. + # Gathered with no entity ceiling, and refused only for the entities + # from 8, which name no user. + 'rank.entities-by-candidates.over': 'The primary keys [8, 9,', 'rank.entities-by-candidates.at': 'The primary keys [8, 9,', 'forecast.top-k': 'a forecast ranks nothing', 'forecast.most-parts': '201 forecast steps means 201 calls', @@ -247,15 +249,14 @@ def test_each_case_is_refused_for_the_argument_it_names() -> None: for case_id, each in recorded.items(): case, _ = cases()[case_id] refused = each['refused'] - assert (refused['outcome'], refused['code']) == ( - 'refused', - case['expect']['code'], - ), case_id + code = ( + 'INVALID_REQUEST' if case_id in DEPARTED else case['expect']['code'] + ) + assert (refused['outcome'], refused['code']) == ('refused', code), ( + case_id + ) assert REFUSED_FOR[case_id] in refused['message'], refused['message'] assert each['change'] == recorder().CONTROLS[case_id] - if case_id == 'rank.entities-by-candidates.at': - # Not vacuous: at 100,000 the ceiling does not refuse. - assert 'in all, is past the' not in refused['message'] assert each['control']['outcome'] == 'result', (case_id, each) @@ -335,6 +336,8 @@ def test_current_client_decomposes_rankings_and_refuses_invalid_arguments( database = case_key.partition('@')[2] or 'duckdb' if database == 'postgres' and not _server(): pytest.skip('Postgres test DSN is not configured') + if case_key.split('@')[0] in DEPARTED: + pytest.skip('a departure from the reference, checked on its own') def check() -> None: run = core_run(database) @@ -684,3 +687,18 @@ def test_float_instance_identity_is_accepted() -> None: assert result['outcome'] == 'result' assert len(result['calls']) == 1 assert len(result['items']) == 2 + + +@pytest.mark.parametrize('case_id', DEPARTED) +def test_python_core_gathers_past_the_reference_s_entity_ceiling( + case_id: str, +) -> None: + r"""Past the reference's 100,000, the ranking is gathered and refused + only for the entities that name no user, as at the ceiling: the + caller's ``INVALID_REQUEST``, not the ceiling's ``UNSUPPORTED_REQUEST``.""" + line = core_run('duckdb').get(case_id) + assert line is not None, f'{case_id}: not observed' + assert (line['outcome']['result'], line['outcome']['code']) == ( + 'refusal', + 'INVALID_REQUEST', + ) diff --git a/docs/reference/limits.md b/docs/reference/limits.md index fc605e8c6..d37ffc554 100644 --- a/docs/reference/limits.md +++ b/docs/reference/limits.md @@ -1,124 +1,44 @@ # Limits -The endpoint enforces several size limits. `materialize()` checks them before -sending, then refuses or samples while naming the limit. Otherwise, a rejected -request returns a 500 or 422 that names neither the limit nor how to meet it. +The client does not enforce the endpoint's size limits: context rows, rows scored per call, request bytes and tables. +A deployment that raises them is not held back. Requests above an endpoint's configured limits may be refused by that endpoint or its gateway. NIM can return detailed limit advice. Databricks Model Serving preserves structured refusal codes but sanitizes some error text. -`Request(context=..., predict=...)` receives exact frames and does not trim -them. It refuses a context above the model's cap instead of discarding named -rows, and reports the count and cap. +## In-process execution and preparation -`materialize()` keeps the context under each model's cap. On `kumo-tabular`, it -samples to the cap and reports the row count. On `kumo-relational`, it gathers -the context. It refuses `num_context_samples` above the cap. Omitting the -argument gathers and reports the 1,000-row budget; it never samples down to -10,000. +`SDMClient.in_process()` has no HTTP endpoint enforcing deployment limits. The client retains conservative sampling and batching defaults, but does not impose a fixed maximum row count based on assumed hardware. Explicitly larger requests must fit available host and device memory. SDM's internal chunking does not guarantee that all inputs fit, including the client's earlier sampling and conversion work. -## Sizes +`query.materialize(..., lag_timesteps=3)` requests three historical target-feature columns. Preparation grows with the number of examples and lag columns, before any model call. Choose the history length needed for the task. Input, date-range and overflow validation remain in place, without a separate fixed lag-memory budget. -Both endpoints enforce sizes, and most of these are the relational one's. +## Defaults -| Limit | Model | Value | Checked | +| Setting | Model | Default | Larger values | |---|---|---|---| -| context rows | relational | 1,000 by default, up to 10,000 with `num_context_samples` | at `materialize()` | -| context rows | tabular | 10,000 | sampled at `materialize()`, refused before sending on a direct `Request` | -| rows scored per call | relational | 10,000 | more are gathered as several calls at `materialize()` | -| entities one question gathers | relational | 100,000, in at most 100 calls | at `materialize()`, and this client's own: the endpoint is never asked for more than one call's worth | -| calls a question asked in parts makes | relational | 200, one per candidate or step | at `materialize()`, as `sdm_client.decompose.MOST_PARTS` | -| request body | relational | 30 MiB per call | at `materialize()` | -| request body | tabular or relational, through Databricks model serving | 16 MB per call, the gateway's own decimal limit | before sending, on the wrapped envelope | -| gradient explanations | relational and tabular | endpoint-dependent; no separate client row/context limit | endpoint validates support | -| hops | relational | 6 | at `materialize()` | -| tables | relational | 15 | against the graph the request carries, not the schema it was built from | - -A client opened with `SDMClient.in_process()` is held to this table as well, -since this client checks it. A NIM also has limits of its own, which each -deployment sets, such as the longest string a cell may hold or the most -distinct values a column may have. Those protect a shared server, and are -not applied when the model runs in your own process. - -A relational request for more entities than one call scores is not refused. -`materialize()` gathers it in batches of at most that many, each with a -context of its own, sampled around that batch's rows rather than copied from -the first, and `predict()` sends one call per batch and returns one result. -Its `row_index` counts across the whole request rather than from zero per -call, so `to_pandas()`, which orders by it, gives the indices back in the -order they were asked for. A session scores those batches against the context -it pinned, so the context is uploaded once rather than once per call. `fit()` -itself takes a request of one call, since a session pins one context: fit a -small request and score the batched one against the handle. - -**The 10,000 is the deployment's, not this client's.** It is the serving -layer's `TFM_MAX_TEST_ROWS`, whose default it is, so a deployment may hold to -less. Measured at the boundary rather than read from a document: 10,000 rows -to score are answered and 10,001 come back as +| context rows | relational | 1,000 | as many as `num_context_samples` asks for | +| context rows | tabular | sampled to 10,000, with a warning | as many as `num_context_samples` asks for; a direct `Request` is sent as given | +| rows scored per call | relational | 10,000 | as many as `rows_per_call` asks for | +| hops | relational | 2, or as `num_hops` / `num_neighbors` ask | at most 6, including the length of an explicit `num_neighbors` list | -``` -422 UNSUPPORTED_SHAPE N_test 10001 exceeds limit 10000 -``` +A relational request for more entities than one call scores is gathered as several calls, each with a context of its own, and `predict()` sends one call per batch and returns one result. +Its `row_index` counts across the whole request, so `to_pandas()` gives the rows back in the order they were asked for. +A session scores those batches against the context it pinned, so the context is uploaded once. +`fit()` takes a request of one call, since a session pins one context. + +The client checks these: + +| Check | Value | +|---|---| +| calls a question asked in parts makes (`sdm_client.decompose.MOST_PARTS`) | 200, one per candidate or step | +| `top_k` | at most 20 | +| a response body | at most 64 MiB | +| a call through Databricks model serving | 16 MB on the wrapped envelope, the gateway's own limit, checked before sending | + +A call that fails ends the request. +The answers already paid for are carried on the error as `details['answered']`, and the rows they cover as `details['rows_answered']`, so the rest can be asked for again. +A forecast keeps its answered steps the same way, under `details['answered']`, numbered by step, with how many under `details['parts_answered']`. +A ranking keeps only the count, because an order over some of its candidates is a different answer. -The earlier `kumo-relational` container holds to 1,000 instead, through a -model-specific admission check of its own, so a request gathered at this -default is refused there on its first call. - -Pass `rows_per_call` to `materialize()` to ask in smaller batches than that. -It only ever goes down, since a larger call buys a 422 rather than a bigger -call. Two reasons to reach for it: a graph wide enough that a full batch -outruns the 30 MiB body, and a deployment whose cap is lower than the one -above. - -It is not the answer to every 30 MiB refusal. A batch carries its context as -well as its rows, so where the context is itself over the limit, no batch is -small enough: a wide graph at 10,000 context rows was refused at every batch -size tried, and the same graph at the default context was gathered as 15 -calls of 200. `num_context_samples`, `num_neighbors` and the columns the graph -carries are what come down in the first case. - -**That 100,000 is this client's, not the endpoint's.** The endpoint is never -asked for more than one call holds. Every batch is built before the first is -sent, each with its own context, so the whole population is held in memory at -once, and 100,000 entities is about a gigabyte of it. One `materialize()` -gathers at most that many, in at most 100 calls, and the refusal names -whichever of the two it met. The second is what a small `rows_per_call` -reaches. - -Both govern the batches of one question, and neither counts the parts of a -question asked in several. A ranking is one call per candidate and a forecast -one per step, and what bounds those is `sdm_client.decompose.MOST_PARTS`, 200, -which is why a 101-candidate ranking makes 101 calls without meeting the 100 -above. What the two ceilings hold for such a question is the population each -part gathers, counted across all of them. - -A call that fails ends the request. The answers already paid for are carried -on the error as `details['answered']`, and the rows they cover as -`details['rows_answered']`, so the rest can be asked for again without buying -the whole population twice. A forecast keeps its answered steps the same way, -under `details['answered']`, numbered by step, with how many of them under -`details['parts_answered']`; a ranking keeps only the count, because an order -over some of its candidates is a different answer rather than part of the one -that was asked for. - -**Batch size is chosen from the row count, not from the bytes.** The 30 MiB -body is checked per batch at `materialize()`, before anything is sent. -Databricks model serving weighs its own wrapped envelope against a smaller -16 MB, and only at send time, so a wide graph can pass `materialize()` and be -refused on the first call. Ask in smaller calls there, with `rows_per_call`, -unless the context alone is over the gateway's limit, which a single-entity -request can be: then it is `num_context_samples`, `num_neighbors` or the -columns the graph carries, as it is for the 30 MiB body. - -**A question asked in parts is not batched.** A ranking is asked as one call -per candidate and a forecast as one per step, and `MOST_PARTS` counts those -calls, so a batched part would send the parts times the batches: a ranking -over 200 candidates and 50,000 entities would pass as 200 calls and make -1,000. More entities than one call scores is refused for both, before -anything is gathered. A ranking could not be batched in any case, since a -candidate is reported unscored for the whole ranking rather than per batch, so -one batch whose context held a single class would drop it from every row. - -The tabular cap was measured at the boundary rather than read from a document: -10,000 context rows are answered and 10,001 come back as -`422 UNSUPPORTED_SHAPE N_train 10001 exceeds limit 10000`. +**A question asked in parts is not batched.** A ranking is asked as one call per candidate and a forecast as one per step, and `MOST_PARTS` counts those calls. +More entities than one call scores is refused for both, before anything is gathered. ## Aggregation windows open after the anchor and close on their last day @@ -150,13 +70,12 @@ values. Omit it on a relational request to use the smaller budget, up to 1,000 examples. This is the endpoint's long-standing default. Omit it on a single-table `materialize()` with either `indices=` or `predict=` to use every -labelled row, up to the endpoint's 10,000-row limit. Above that, it samples -10,000 rows and reports doing so. Use the argument to request more. +labelled row, up to 10,000. Above that, it samples 10,000 rows and reports +doing so. Use the argument to request more. Ask for more than exists and you get what exists; there are only so many -labelled examples, and that is not an error. Ask for more than 10,000 and you -are told the ceiling rather than silently given fewer. Zero, a negative, a -fraction or a string are refused by name. +labelled examples, and that is not an error. Zero, a negative, a fraction or a +string are refused by name. **Which examples you get** when the count narrows: the first `n` of what was gathered, and for a temporal question that is **not a sample across time**. diff --git a/java/src/main/java/com/nvidia/sdm/internal/Wording.java b/java/src/main/java/com/nvidia/sdm/internal/Wording.java index 50ae80ad6..4a1158a6e 100644 --- a/java/src/main/java/com/nvidia/sdm/internal/Wording.java +++ b/java/src/main/java/com/nvidia/sdm/internal/Wording.java @@ -99,7 +99,6 @@ private static Map, String>> advice() { + ") && List.of(" + String.join(", ", quotedAll(given.get(2))) + ").contains(link.sourceColumn()))).toList())"); - spelled.put("materialize_call", given -> "materialize()"); spelled.put("missing_time", given -> "null"); spelled.put( "name_candidates", @@ -135,9 +134,6 @@ private static Map, String>> advice() { given -> "Name another key with FromSourceOptions.builder().primaryKey(...), or pass" + " checkKeys(false) to skip (one full scan per table)."); - spelled.put( - "smaller_calls", - given -> "MaterializeOptions.builder().option(\"rows_per_call\", N)"); spelled.put("trust_expressions", given -> "semanticModel(name, true)"); return Map.copyOf(spelled); } diff --git a/java/src/test/java/com/nvidia/sdm/RelationalTest.java b/java/src/test/java/com/nvidia/sdm/RelationalTest.java index 0bf4047b2..eaa746f24 100644 --- a/java/src/test/java/com/nvidia/sdm/RelationalTest.java +++ b/java/src/test/java/com/nvidia/sdm/RelationalTest.java @@ -38,6 +38,23 @@ /** Public multi-table journeys through Java, JNI, the shared sampler and an HTTP endpoint. */ class RelationalTest { + @Test void samplingAcceptsSixHopsAndRefusesSeven() throws Exception { + Schema schema = fixture(false, false); + PredictiveQuery query = PredictiveQuery.parse(SCALAR); + for (String field : List.of("num_hops", "num_neighbors")) { + Object six = field.equals("num_hops") ? 6 : Collections.nCopies(6, 2); + Object seven = field.equals("num_hops") ? 7 : Collections.nCopies(7, 2); + Request request = query.materialize(schema, options(1L, 2L).option(field, six).build()); + assertEquals(2, request.predictRows()); + StructuredDataException error = assertThrows(StructuredDataException.class, + () -> query.materialize(schema, options(1L, 2L).option(field, seven).build())); + assertEquals("UNSUPPORTED_REQUEST", error.code()); + assertEquals(field, error.details().get("field")); + assertEquals(6, ((Number) error.details().get("limit")).intValue()); + assertTrue(error.getMessage().contains("at most 6 hops")); + } + } + @Test void sanitizationReportSurvivesRequestPersistence() throws Exception { Schema schema = fixture(false, false); Request request = PredictiveQuery.parse(SCALAR).materialize(schema, options(1L, 2L).build()); diff --git a/packages/structured-data-models-client/src/sdm_client/_rust/errors.py b/packages/structured-data-models-client/src/sdm_client/_rust/errors.py index 1ca231ec9..a22fedbb0 100644 --- a/packages/structured-data-models-client/src/sdm_client/_rust/errors.py +++ b/packages/structured-data-models-client/src/sdm_client/_rust/errors.py @@ -68,15 +68,12 @@ } #: The refusals the reference raises as its base class under their code, -#: by code and rule: ``main``'s 1fc5a686 ceilings on what one -#: ``materialize`` gathers and its refusal of a batched forecast, each a +#: by code and rule: ``main``'s 1fc5a686 refusal of a batched forecast, a #: ``StructuredDataError(code='UNSUPPORTED_REQUEST')`` in the reference's #: client, so a caller's ``except`` sees the class it would there ( fix #: 2). Every other refusal takes its code's class (data:`ERRORS`). AS_THE_BASE_CLASS: frozenset[tuple[str, str]] = frozenset( { - ('UNSUPPORTED_REQUEST', 'most_entities'), - ('UNSUPPORTED_REQUEST', 'most_calls'), ('UNSUPPORTED_REQUEST', 'batched_part'), } ) @@ -143,7 +140,6 @@ class UserWarning(builtins.UserWarning): # noqa: A001 - the reference's name f'not (link.source_table == {source!r} and link.target_table == ' f'{target!r} and link.source_column in {others!r})]' ), - 'materialize_call': lambda: 'materialize()', 'name_candidates': lambda column: ( f'materialize(..., candidates=frame[{column!r}])' ), @@ -165,7 +161,6 @@ class UserWarning(builtins.UserWarning): # noqa: A001 - the reference's name ), 'missing_time': lambda: "'NaT'", 'result_frame': lambda: 'to_pandas()', - 'smaller_calls': lambda: 'materialize(rows_per_call=N)', 'trust_expressions': lambda: 'trust_expressions=True', } diff --git a/packages/structured-data-models-client/src/sdm_client/_rust/frame_materialize.py b/packages/structured-data-models-client/src/sdm_client/_rust/frame_materialize.py index 0582c9574..6052fdbef 100644 --- a/packages/structured-data-models-client/src/sdm_client/_rust/frame_materialize.py +++ b/packages/structured-data-models-client/src/sdm_client/_rust/frame_materialize.py @@ -104,7 +104,6 @@ def _gather_locked( candidates: Sequence[Any] | None, ) -> tuple[tuple[dict[str, Any], ...], results.QueryFacts, results.CoreRequest]: from sdm_client import decompose - from sdm_client.materializers import relational anchor = options.get('anchor_time') call = { @@ -116,8 +115,6 @@ def _gather_locked( 'unseeded': 'random_seed' in options and options['random_seed'] is None, 'options': sorted(set(options) - TAKEN), 'most_parts': max(0, min(int(decompose.MOST_PARTS), 2**32 - 1)), - 'most_entities': max(0, min(int(relational.MOST_ENTITIES), 2**64 - 1)), - 'most_calls': max(0, min(int(relational.MOST_CALLS), 2**32 - 1)), } attachments = { 1: _graph(materializer), diff --git a/packages/structured-data-models-client/src/sdm_client/_rust/materialize.py b/packages/structured-data-models-client/src/sdm_client/_rust/materialize.py index 4c62bd3f9..b226618ac 100644 --- a/packages/structured-data-models-client/src/sdm_client/_rust/materialize.py +++ b/packages/structured-data-models-client/src/sdm_client/_rust/materialize.py @@ -289,9 +289,7 @@ def gather( A request of more entities than one call scores is gathered by the core as several calls (``main``'s 1fc5a686): its payloads are each call's, in order, and the state keeps how many rows each later call - scores. The most entities and calls one ``materialize`` holds are this - client's (``MOST_ENTITIES``, ``MOST_CALLS``), which the core holds the - call to. + scores, however many entities there are. Raises: StructuredDataError: The core's refusal, as:mod:`.errors` maps it, @@ -344,14 +342,6 @@ def gather( }, ), } - # The ceilings on what one materialize holds, which the caller may set - # as it sets the most steps of a forecast. - from sdm_client.materializers import relational - - operation['most_entities'] = max( - 0, min(int(relational.MOST_ENTITIES), 2**64 - 1) - ) - operation['most_calls'] = max(0, min(int(relational.MOST_CALLS), 2**32 - 1)) if candidates is not None: operation['candidates'] = 6 attachments[6] = codec.attachment(_candidates(candidates)) diff --git a/packages/structured-data-models-client/src/sdm_client/_rust/tabular_materialize.py b/packages/structured-data-models-client/src/sdm_client/_rust/tabular_materialize.py index 9b15ae10f..b750a50f7 100644 --- a/packages/structured-data-models-client/src/sdm_client/_rust/tabular_materialize.py +++ b/packages/structured-data-models-client/src/sdm_client/_rust/tabular_materialize.py @@ -215,39 +215,21 @@ def _context( has_custom_sorter, observe, ) - from sdm_client.models import TABULAR_LIMITS - limit = TABULAR_LIMITS['context_rows_max'] + # Sampled to the count asked for, else to the core's default. if decision is None: - over_limit = wanted is not None and bool(wanted > limit) - accepted = _call('check_tabular_cap', {'over_limit': over_limit})[ - 'accepted' - ] - if not accepted: - decision = {'kind': 'refused'} - else: - count = int(wanted) if isinstance(wanted, np.integer) else wanted - decision = _call( - 'decide_tabular_context', - { - 'population': len(candidates), - 'requested': count, - }, - ) - if decision['kind'] == 'refused': - raise StructuredDataError( - f'num_context_samples is {wanted:,}, and the ' - f'endpoint accepts at most {limit:,} context rows', - code='UNSUPPORTED_REQUEST', + count = int(wanted) if isinstance(wanted, np.integer) else wanted + decision = _call( + 'decide_tabular_context', + {'population': len(candidates), 'requested': count}, ) if not decision['reduced']: return candidates if decision['advise_default_reduction']: count = decision['wanted'] warnings.warn( - f'{table} has {len(candidates):,} rows that could be context and ' - f'the endpoint accepts {count:,}, so {count:,} were ' - f'sampled. {remedy}', + f'{table} has {len(candidates):,} rows that could be context, ' + f'so {count:,}, the default, were sampled. {remedy}', category=SDMWarning, stacklevel=caller_stacklevel(), ) diff --git a/packages/structured-data-models-client/src/sdm_client/materializers/relational.py b/packages/structured-data-models-client/src/sdm_client/materializers/relational.py index b18afcfe9..615c51cf6 100644 --- a/packages/structured-data-models-client/src/sdm_client/materializers/relational.py +++ b/packages/structured-data-models-client/src/sdm_client/materializers/relational.py @@ -19,11 +19,6 @@ from sdm_client.sanitization import SanitizationReport -# Host memory limits passed to Rust for request-size enforcement. -MOST_ENTITIES = 100_000 -MOST_CALLS = 100 - - class RelationalMaterializer: """Retain host resources while Rust owns sampling and request construction.""" diff --git a/packages/structured-data-models-client/src/sdm_client/models.py b/packages/structured-data-models-client/src/sdm_client/models.py index 3cc4c9261..c2790188e 100644 --- a/packages/structured-data-models-client/src/sdm_client/models.py +++ b/packages/structured-data-models-client/src/sdm_client/models.py @@ -42,27 +42,10 @@ from sdm_client.base import ModelSpec, RuntimeContract from sdm_client.errors import StructuredDataError, UnknownModelError -# Sizes the relational endpoint enforces. `predict_rows_max` is the serving -# layer's own `TFM_MAX_TEST_ROWS`, measured at the boundary rather than read -# from a document: 10,000 rows to score are answered, and 10,001 come back -# -# [422 UNSUPPORTED_SHAPE] N_test 10001 exceeds limit 10000. -# -# A deployment may be configured to hold to less, which is what the -# `rows_per_call` option on materialize() is for. -# -# The endpoint refuses past these, so the client refuses first with a message -# that names the limit. See the architecture note on inference knobs: -# `run_mode` is derived from these rather than being set. -# -# Prediction row limits also bound the batches requested from the Rust core. -# Keep endpoint limits and batching consistent so each batch is accepted. +# Fixed properties of the relational model. The client holds a request to no +# size of its own: the endpoint's limits are the endpoint's to enforce. RELATIONAL_LIMITS = { 'context_rows_fast': 1_000, - 'context_rows_max': 10_000, - 'predict_rows_max': 10_000, - 'hops_max': 6, - 'tables_max': 15, 'classes_max': 10, } @@ -73,18 +56,6 @@ PREDICTION_STATISTICS = frozenset({'mean', 'median'}) SUMMARISED_TASK_KINDS = frozenset({'regression', 'forecasting'}) -# The tabular endpoint refuses a context past this, exactly: -# -# [422 UNSUPPORTED_SHAPE] N_train 10001 exceeds limit 10000. -# -# Measured against the deployment rather than read from a document, at the -# boundary: 10,000 rows answer, 10,001 refuse. Declared so the client refuses -# first, because the alternative is encoding and transmitting an arbitrarily -# large context to be told the limit at the far end. -TABULAR_LIMITS = { - 'context_rows_max': 10_000, -} - KUMO_TABULAR = ModelSpec( model_id=TFM_MODEL_KUMO_TABULAR, profile='TABULAR', @@ -95,7 +66,6 @@ outputs=frozenset( {'prediction', 'probabilities', 'quantiles', 'explanation'} ), - limits=TABULAR_LIMITS, explanation_formats=('sdm_gradient_v1',), ), ) diff --git a/packages/structured-data-models-client/src/sdm_client/query.py b/packages/structured-data-models-client/src/sdm_client/query.py index ff5e048c6..f4032bd62 100644 --- a/packages/structured-data-models-client/src/sdm_client/query.py +++ b/packages/structured-data-models-client/src/sdm_client/query.py @@ -193,11 +193,8 @@ def materialize( and ``anchor_time``; ``prediction_statistic``: what a regression's prediction reports of its predicted distribution, ``'median'`` (the default) or ``'mean'``; and - ``rows_per_call``: how many entities one call scores, which - defaults to what the endpoint takes, 10,000, and may only be - lowered. Lower it for a graph wide enough that a full batch - outruns the 30 MiB body, or for a deployment holding to less - than this client knows of. + ``rows_per_call``: how many entities one call scores, 10,000 + by default, taken as asked. Returns: A:class:`~sdm_client.Request` carrying the data. diff --git a/packages/structured-data-models-client/tests/tabular_pql_count_cases.py b/packages/structured-data-models-client/tests/tabular_pql_count_cases.py index 85baf1abd..98d023a01 100644 --- a/packages/structured-data-models-client/tests/tabular_pql_count_cases.py +++ b/packages/structured-data-models-client/tests/tabular_pql_count_cases.py @@ -34,10 +34,9 @@ class StopWarning(Exception): def observe_case(name: str) -> dict[str, Any]: from sdm_client import KumoTabular, PredictiveQuery, SDMClient - from sdm_client.models import TABULAR_LIMITS assert name in CASES - cap = TABULAR_LIMITS['context_rows_max'] + cap = 10_000 events: list[Any] = [] recorded: list[dict[str, str]] = [] outcome: dict[str, Any] = {} diff --git a/packages/structured-data-models-client/tests/test_a_remedy_is_followed_to_the_wire.py b/packages/structured-data-models-client/tests/test_a_remedy_is_followed_to_the_wire.py index 360cfa4ef..0e9941336 100644 --- a/packages/structured-data-models-client/tests/test_a_remedy_is_followed_to_the_wire.py +++ b/packages/structured-data-models-client/tests/test_a_remedy_is_followed_to_the_wire.py @@ -256,7 +256,7 @@ def test_the_limits_page_records_the_default_the_code_has() -> None: Path(__file__).resolve().parents[3] / 'docs' / 'reference' / 'limits.md' ).read_text() assert '1,000 when explaining, otherwise 10,000' not in page - assert '1,000 by default, up to 10,000 with `num_context_samples`' in page + assert '| context rows | relational | 1,000 |' in page def test_a_concrete_timestamp_materializes() -> None: diff --git a/packages/structured-data-models-client/tests/test_asked_in_the_questions_it_serves.py b/packages/structured-data-models-client/tests/test_asked_in_the_questions_it_serves.py index 641cc7926..b34edd12f 100644 --- a/packages/structured-data-models-client/tests/test_asked_in_the_questions_it_serves.py +++ b/packages/structured-data-models-client/tests/test_asked_in_the_questions_it_serves.py @@ -97,9 +97,7 @@ def test_more_entities_than_one_call_scores_is_refused_before_gathering( ): """A part is one call, which is what makes the fan-out countable. The refusal reads the count it was given, so it costs no gathering.""" - from sdm_client.models import RELATIONAL_LIMITS - - count = RELATIONAL_LIMITS['predict_rows_max'] + 1 + count = 10_000 + 1 # one past the default batch with pytest.raises(StructuredDataError) as refused: built(query, indices=[1] * count, **how) assert refused.value.code == 'UNSUPPORTED_REQUEST' @@ -108,8 +106,8 @@ def test_more_entities_than_one_call_scores_is_refused_before_gathering( def test_a_smaller_batch_lowers_what_a_part_may_ask_for(monkeypatch): - """`rows_per_call` only goes down, and a part is one call, so asking for a - smaller one asks for fewer entities rather than for more calls.""" + """A part is one call, so asking for a smaller ``rows_per_call`` asks for + fewer entities rather than for more calls.""" with pytest.raises(StructuredDataError) as refused: built(FORECAST, indices=[1, 2, 3], rows_per_call=2) @@ -117,22 +115,6 @@ def test_a_smaller_batch_lowers_what_a_part_may_ask_for(monkeypatch): assert built(FORECAST, indices=[1, 2], rows_per_call=2).parts -def test_the_whole_decomposed_question_is_held_to_the_memory_ceiling( - monkeypatch, -): - """Each part gathers the whole population with a context of its own, so a - ranking over 200 candidates holds 200 times what one of them does. Bounding - each part on its own left the question itself unbounded.""" - from sdm_client.materializers import relational as materializer - - monkeypatch.setattr(materializer, 'MOST_ENTITIES', 5) - built(RANK, indices=[1, 2], candidates=[0, 1]) - with pytest.raises(StructuredDataError) as refused: - built(RANK, indices=[1, 2, 3], candidates=[0, 1]) - assert refused.value.details['total'] == 6 - assert refused.value.details['gathered_times'] == 2 - - def test_a_step_that_fails_keeps_the_steps_already_paid_for(): """A question asked in parts pays per part, and the steps answered before a failure are as bought as the batches of one are. diff --git a/packages/structured-data-models-client/tests/test_context_samples.py b/packages/structured-data-models-client/tests/test_context_samples.py index d41d87c62..3b00f930d 100644 --- a/packages/structured-data-models-client/tests/test_context_samples.py +++ b/packages/structured-data-models-client/tests/test_context_samples.py @@ -25,7 +25,7 @@ from sdm_client.models import RELATIONAL_LIMITS FAST = RELATIONAL_LIMITS['context_rows_fast'] -MAX = RELATIONAL_LIMITS['context_rows_max'] +MAX = 10_000 # --- which value goes on the wire ----------------------------------------- @@ -41,6 +41,7 @@ (FAST + 1, 'best'), (MAX - 1, 'best'), (MAX, 'best'), + (MAX + 1, 'best'), ], ) def test_the_wire_value_is_the_one_that_admits_the_count(asked, expected): @@ -49,20 +50,6 @@ def test_the_wire_value_is_the_one_that_admits_the_count(asked, expected): assert request._payloads[0]['inference']['run_mode'] == expected -def test_asking_for_more_than_the_endpoint_allows_names_the_ceiling(): - with pytest.raises(StructuredDataError) as error: - _materialize(num_context_samples=MAX + 1) - message = str(error.value) - assert '10,000' in message - assert error.value.code == 'UNSUPPORTED_REQUEST' - - -def test_the_boundary_is_at_the_documented_row_counts(): - """A pin: these are the two numbers the endpoint actually distinguishes.""" - assert FAST == 1_000 - assert MAX == 10_000 - - # --- how many examples are actually gathered ------------------------------ diff --git a/packages/structured-data-models-client/tests/test_databricks_from_source.py b/packages/structured-data-models-client/tests/test_databricks_from_source.py index 1c13272cd..2c4549e1e 100644 --- a/packages/structured-data-models-client/tests/test_databricks_from_source.py +++ b/packages/structured-data-models-client/tests/test_databricks_from_source.py @@ -1745,25 +1745,6 @@ def test_refusals_preserve_source_read_order( assert _where_read(schema, connection) == {where} -def test_too_many_entities_are_refused_before_the_source_is_read( - monkeypatch: pytest.MonkeyPatch, -) -> None: - r"""More entities than one ``materialize`` holds are refused from the - count alone, before the old route's engine reads anything - (``relational.py:339``): the tracker's entity-count row.""" - from sdm_client.errors import StructuredDataError - from sdm_client.materializers import relational - - monkeypatch.setattr(relational, 'MOST_ENTITIES', 1) - connection = _CompletingConnection() - schema = _rebuilt(connection) - mark = len(connection.calls) - with pytest.raises(StructuredDataError) as refused: - _asked(schema) - assert refused.value.code == 'UNSUPPORTED_REQUEST' - assert len(connection.calls) == mark - - class _EmptyingWarehouse(_CompletingWarehouse): r"""The completing warehouse, whose ``shop.users`` holds no row while ``empty`` says so: every read of its rows answers none, and its count diff --git a/packages/structured-data-models-client/tests/test_databricks_serving.py b/packages/structured-data-models-client/tests/test_databricks_serving.py index 693a4368f..c4afaabf9 100644 --- a/packages/structured-data-models-client/tests/test_databricks_serving.py +++ b/packages/structured-data-models-client/tests/test_databricks_serving.py @@ -466,6 +466,45 @@ def test_an_oversized_request_is_refused_before_it_is_sent(): assert 'rows to score' in str(error.value) +def test_default_gateway_limit_accepts_exact_bytes_then_refuses_one_more(): + """Check the client guard, not a hosted gateway or model's acceptance.""" + limit = 16_000_000 + + def encoded_size(payload): + records = [{'request_json': json.dumps(payload, separators=(',', ':'))}] + return len( + json.dumps( + {'dataframe_records': records}, separators=(',', ':') + ).encode('utf-8') + ) + + payload = {'text': ''} + payload['text'] = 'x' * (limit - encoded_size(payload)) + assert encoded_size(payload) == limit + workspace = Workspace(answer={'predictions': []}) + transport = DatabricksServingTransport(ENDPOINT, workspace) + try: + assert transport.predict(payload) == {'predictions': []} + assert len(workspace.serving_endpoints.calls) == 1 + records = workspace.serving_endpoints.calls[0]['dataframe_records'] + assert ( + len( + json.dumps( + {'dataframe_records': records}, separators=(',', ':') + ).encode('utf-8') + ) + == limit + ) + payload['text'] += 'x' + with pytest.raises(StructuredDataError) as error: + transport.predict(payload) + assert error.value.code == 'INVALID_REQUEST' + assert error.value.details == {'bytes': limit + 1, 'limit': limit} + assert len(workspace.serving_endpoints.calls) == 1 + finally: + transport.close() + + def test_the_size_counted_is_the_wrapped_envelope_not_the_payload(): """Every quote is escaped again once the payload is a string inside the envelope, so a payload under the limit can be over it on the wire.""" diff --git a/packages/structured-data-models-client/tests/test_limits_and_absent_outputs.py b/packages/structured-data-models-client/tests/test_limits_and_absent_outputs.py index 33e837fe8..0f578032a 100644 --- a/packages/structured-data-models-client/tests/test_limits_and_absent_outputs.py +++ b/packages/structured-data-models-client/tests/test_limits_and_absent_outputs.py @@ -4,10 +4,9 @@ """What the endpoint will not take, and what the answer did not contain. -Two silences. The tabular endpoint caps a context at 10,000 rows and the client -did not know it, so a caller could encode and transmit a table of any size to -be refused at the far end, while the identical overage on the other model was -refused locally with a message naming the limit. +The context the client sends: sampled to 10,000 rows by default, or to the +count the caller names, which the client holds to no size of its own; a +context larger than the endpoint takes is the endpoint's refusal. And a field a caller names is validated against the model and never against what comes back. The endpoint answers 200, leaves the field out, and the frame @@ -27,7 +26,6 @@ from sdm_client import PredictiveQuery, Schema from sdm_client.client import _report_absent from sdm_client.errors import StructuredDataError -from sdm_client.models import KUMO_TABULAR from sdm_client.result import PredictionResult @@ -59,16 +57,12 @@ def query(schema: Schema) -> PredictiveQuery: # --- the context the endpoint will take ------------------------------------ -def test_the_declared_cap_is_the_one_the_endpoint_enforces(): - """Measured at the boundary: 10,000 answer, 10,001 refuse.""" - assert KUMO_TABULAR.runtime.limits['context_rows_max'] == 10_000 - - -def test_a_context_above_the_cap_is_refused_before_it_is_encoded(): +def test_a_count_past_the_rows_there_takes_them_all(): schema = table(200) - with pytest.raises(StructuredDataError) as raised: - query(schema).materialize(indices=[0, 1], num_context_samples=50_000) - assert 'accepts at most 10,000 context rows' in str(raised.value) + request = query(schema).materialize( + indices=[0, 1], num_context_samples=50_000 + ) + assert len(request.context.instance_table) == 198 def test_the_cap_itself_is_allowed(): @@ -220,13 +214,13 @@ def test_the_result_is_returned_unchanged(): assert _report_absent(answer, ['quantiles'], 'kumo-x') is answer -def test_a_materialized_context_above_the_cap_is_refused_not_merely_the_number(): - """A small table makes this a check on the argument. The rows have to be - there for it to be a check on the context.""" +def test_a_count_past_the_default_is_gathered(): + """The rows are there, so the count is the context's size.""" schema = table(12_000) - with pytest.raises(StructuredDataError) as raised: - query(schema).materialize(indices=[0, 1], num_context_samples=10_001) - assert 'accepts at most 10,000 context rows' in str(raised.value) + request = query(schema).materialize( + indices=[0, 1], num_context_samples=10_001 + ) + assert len(request.context.instance_table) == 10_001 def test_the_predict_route_advises_something_that_route_allows(): @@ -397,15 +391,14 @@ def test_a_target_that_varies_is_left_alone(): assert not any('every context row' in s for s in said) -def test_a_context_past_the_models_cap_is_refused_before_it_is_sent(): - """The client's own preamble says it refuses first where it can tell, and - the model is known by the time this check runs, so sending 12,500 rows to - be told the limit at the far end was work nobody needed to do.""" +def test_a_context_past_10_000_rows_is_sent(): + """The client holds a context to no size of its own: 12,500 rows are + sent, for the endpoint to answer or refuse.""" import numpy as np import pandas as pd from test_adapter_and_result import envelope - from sdm_client import Request, UnsupportedRequestError + from sdm_client import Request rng = np.random.default_rng(0) rows = 12_500 @@ -418,8 +411,7 @@ def test_a_context_past_the_models_cap_is_refused_before_it_is_sent(): task='classification', ) - with pytest.raises(UnsupportedRequestError, match='12,500'): - envelope(request) + envelope(request) def test_a_context_within_the_cap_is_not_refused(): diff --git a/packages/structured-data-models-client/tests/test_limits_and_sessions.py b/packages/structured-data-models-client/tests/test_limits_and_sessions.py index 97ac9f8e8..6e288537e 100644 --- a/packages/structured-data-models-client/tests/test_limits_and_sessions.py +++ b/packages/structured-data-models-client/tests/test_limits_and_sessions.py @@ -2,12 +2,7 @@ # All rights reserved. # SPDX-License-Identifier: Apache-2.0 -"""What the client refuses before spending a round trip, and how sessions behave. - -The endpoint enforces several sizes, and a request past one of them comes back -as a 500 or a 422 that names neither the limit nor how to get under it. Every -check here exists so the caller reads a sentence instead. -""" +"""Client sampling boundaries and session behavior through public APIs.""" from __future__ import annotations @@ -19,7 +14,7 @@ from sdm_client import Schema, UnsupportedRequestError from sdm_client.errors import StructuredDataError -from sdm_client.models import KUMO_RELATIONAL, RELATIONAL_LIMITS +from sdm_client.models import KUMO_RELATIONAL def payload(*, predict_rows: int, context_rows: int) -> dict: @@ -54,20 +49,6 @@ def _Gathered(*payloads): ) -def test_the_declared_limits_are_pinned_to_what_was_read_off_the_endpoint(): - """A pin, not a probe. - - These numbers were read from the relational NIM. This asserts they have - not drifted in the client, which is all it can do offline. The live suites - check that the endpoint still agrees. - """ - assert RELATIONAL_LIMITS['context_rows_fast'] == 1_000 - assert RELATIONAL_LIMITS['context_rows_max'] == 10_000 - assert RELATIONAL_LIMITS['predict_rows_max'] == 10_000 - assert RELATIONAL_LIMITS['hops_max'] == 6 - assert RELATIONAL_LIMITS['tables_max'] == 15 - - @pytest.mark.parametrize('bad', ['2', True]) def test_num_hops_must_be_a_whole_number(bad): from test_frame_sessions_core import query @@ -80,6 +61,31 @@ def test_num_hops_must_be_a_whole_number(bad): assert error.value.code == 'INVALID_REQUEST' +@pytest.mark.parametrize('field', ['num_hops', 'num_neighbors']) +def test_sampling_accepts_six_hops_and_refuses_seven(field): + from test_frame_sessions_core import query + + from sdm_client import KumoRelational + + def options(depth): + return {field: depth if field == 'num_hops' else [2] * depth} + + materializer = query() + request = materializer.materialize( + indices=[1], model=KumoRelational(), **options(6) + ) + assert len(request.payloads) == 1 + assert len(request.payloads[0]['predict']['instance_table']['rows']) == 1 + with pytest.raises(UnsupportedRequestError) as error: + materializer.materialize( + indices=[1], model=KumoRelational(), **options(7) + ) + assert error.value.code == 'UNSUPPORTED_REQUEST' + assert error.value.details['field'] == field + assert error.value.details['limit'] == 6 + assert 'at most 6 hops' in str(error.value) + + @pytest.mark.parametrize( ('predict_rows', 'context_rows'), [(4, 100), (1, 5000)] ) @@ -246,20 +252,10 @@ def gathered_in_calls(*, calls: int, context_rows: int): ) -@pytest.mark.parametrize('over', [False, True], ids=['under', 'over']) -def test_the_context_cap_is_held_to_each_call_and_not_their_sum(over): - """Both sides of the cap, because only the allowed one was covered: a - per-call count that always read nought would have passed that alone.""" - - cap = RELATIONAL_LIMITS['context_rows_max'] - each = cap + 1 if over else cap // 2 + 1 - request = gathered_in_calls(calls=2, context_rows=each) - if not over: - sent(request) - return - with pytest.raises(StructuredDataError) as refused: - sent(request) - assert f'{each:,} context rows' in str(refused.value) +def test_each_call_s_context_is_sent_at_any_size(): + """The client holds a context to no size of its own, in each call or + across them.""" + sent(gathered_in_calls(calls=2, context_rows=10_001)) def test_a_batched_request_reports_the_context_one_call_carries(): diff --git a/packages/structured-data-models-client/tests/test_live_relational.py b/packages/structured-data-models-client/tests/test_live_relational.py index dbe6d44cd..c603baf41 100644 --- a/packages/structured-data-models-client/tests/test_live_relational.py +++ b/packages/structured-data-models-client/tests/test_live_relational.py @@ -179,33 +179,6 @@ def test_an_aggregation_wider_than_the_history_is_refused_locally(client): assert 'data' in str(error.value).lower() -@requires_relational -def test_the_endpoint_scores_what_this_client_says_it_does(client, query): - """The per-call cap is the endpoint's, and batching is sized from it, so a - drift sends batches it refuses. Asked at the boundary: one row past the - cap is refused, and the refusal names the cap this client holds to. - - One past, and not the cap itself, because the rows here are repeated to - reach that size and a payload of 10,000 repeated keys is refused for the - repetition instead. That the cap is answered was measured separately, - against a graph with that many distinct entities in it. - """ - import copy - - from sdm_client.models import RELATIONAL_LIMITS - - cap = RELATIONAL_LIMITS['predict_rows_max'] - payload = copy.deepcopy(query.materialize(indices=[0, 1]).payloads[0]) - rows = payload['predict']['instance_table']['rows'] - - payload['predict']['instance_table']['rows'] = [ - list(rows[i % len(rows)]) for i in range(cap + 1) - ] - with pytest.raises(StructuredDataError) as refused: - client._transport.predict(payload) - assert str(cap) in str(refused.value) - - @requires_relational def test_more_entities_than_one_call_scores_come_back_as_one_answer( client, query diff --git a/packages/structured-data-models-client/tests/test_live_row_limits.py b/packages/structured-data-models-client/tests/test_live_row_limits.py new file mode 100644 index 000000000..25385ae7c --- /dev/null +++ b/packages/structured-data-models-client/tests/test_live_row_limits.py @@ -0,0 +1,132 @@ +# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. +# All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +"""Public-client boundary pairs against a dedicated, configured deployment. + +Run with -m live_nim and SDM_LIMIT_TEST_MODEL=kumo-tabular or kumo-relational. +Set SDM_LIMIT_TEST_URL for NIM, or SDM_LIMIT_TEST_ENDPOINT and +SDM_LIMIT_TEST_PROFILE for Databricks. Set SDM_LIMIT_TEST_CONTEXT_ROWS and +SDM_LIMIT_TEST_PREDICT_ROWS to the deployment's confirmed effective limits. +Use small limits on dedicated endpoints. This suite never configures a server. +Each test predicts at the limit before asking for one more row. +""" + +import os + +import numpy as np +import pandas as pd +import pytest + +from sdm_client import ( + KumoRelational, + KumoTabular, + PredictiveQuery, + Schema, + SDMClient, +) +from sdm_client.errors import NimRequestError + +pytestmark = pytest.mark.live_nim + + +def request_for(context_rows, predict_rows, model): + count = context_rows + predict_rows + indices = list(range(context_rows, count)) + tables = { + 'users': pd.DataFrame( + { + 'id': range(count), + 'feature': [i * 2.5 for i in range(count)], + 'value': [i * 1.25 for i in range(context_rows)] + + [None] * predict_rows, + } + ) + } + keys = {'users': 'id'} + if isinstance(model, KumoRelational): + tables['events'] = pd.DataFrame( + { + 'event': range(count), + 'id': range(count), + 'feature': [i * 2.5 for i in range(count)], + } + ) + keys['events'] = 'event' + schema = Schema.from_data(tables, primary_keys=keys) + schema['users']['value'].stype = 'numerical' + schema['users']['feature'].stype = 'numerical' + options = ( + {'rows_per_call': predict_rows} + if isinstance(model, KumoRelational) + else {} + ) + request = PredictiveQuery( + 'PREDICT users.value FOR EACH users.id', schema + ).materialize( + model=model, + indices=indices, + num_context_samples=context_rows, + **options, + ) + # Prevent sampling or automatic batching from hiding the tested boundary. + assert request.context_rows == context_rows + assert request.predict_rows == predict_rows + if isinstance(model, KumoRelational): + assert len(request.payloads) == 1 + return request, indices + + +@pytest.mark.parametrize('axis', ['context', 'predict']) +def test_exact_row_limit_succeeds_then_one_more_is_refused(axis): + name = os.environ.get('SDM_LIMIT_TEST_MODEL') + limit_text = os.environ.get(f'SDM_LIMIT_TEST_{axis.upper()}_ROWS') + if not name or not limit_text: + pytest.skip('set the dedicated model and confirmed row limit') + models = {'kumo-tabular': KumoTabular, 'kumo-relational': KumoRelational} + assert name in models, 'use an actual supported model, not a prototype' + limit = int(limit_text) + assert limit >= 2 + model = models[name]() + endpoint = os.environ.get('SDM_LIMIT_TEST_ENDPOINT') + if endpoint: + assert endpoint not in {'kumo-score', 'kumo-score-probe'} + from databricks.sdk import WorkspaceClient + + client = SDMClient.for_databricks_serving( + endpoint, + workspace_client=WorkspaceClient( + profile=os.environ['SDM_LIMIT_TEST_PROFILE'] + ), + ) + else: + client = SDMClient(url=os.environ['SDM_LIMIT_TEST_URL']) + with client: + counts = { + 'context': min( + 8, int(os.environ.get('SDM_LIMIT_TEST_CONTEXT_ROWS', '8')) + ), + 'predict': 1, + } + counts[axis] = limit + request, indices = request_for( + counts['context'], counts['predict'], model + ) + frame = client.predict(request, model=model).to_pandas() + assert len(frame) == counts['predict'] + assert frame['row_index'].tolist() == list(range(counts['predict'])) + assert frame['id'].astype(str).tolist() == [str(i) for i in indices] + assert np.isfinite(frame['prediction'].to_numpy(dtype=float)).all() + + counts[axis] += 1 + oversized, _ = request_for(counts['context'], counts['predict'], model) + with pytest.raises(NimRequestError) as refused: + client.predict(oversized, model=model) + assert refused.value.code == 'UNSUPPORTED_SHAPE' + if endpoint: + assert refused.value.status_code >= 400 + assert endpoint in str(refused.value) + else: + assert refused.value.status_code == 422 + assert f'{axis}.instance_table' in str(refused.value) + assert f'exceeds limit {limit}' in str(refused.value) diff --git a/packages/structured-data-models-client/tests/test_materialize_options.py b/packages/structured-data-models-client/tests/test_materialize_options.py index 0c2e91ec5..10f638a55 100644 --- a/packages/structured-data-models-client/tests/test_materialize_options.py +++ b/packages/structured-data-models-client/tests/test_materialize_options.py @@ -372,21 +372,8 @@ def _refusal_of(**options: Any) -> StructuredDataError: def test_a_limit_is_raised_as_the_subclass_on_the_core_register_p1b_20() -> ( None ): - for options in ({'num_context_samples': 10001}, {'num_hops': 7}): - core = _refusal_of(**options) - assert core.code == 'UNSUPPORTED_REQUEST', options - assert type(core).__name__ == 'UnsupportedRequestError', options - assert 'rule' not in core.details, options - for options, rule in ( - ({'indices': list(range(100001))}, 'most_entities'), - ({'indices': list(range(101)), 'rows_per_call': 1}, 'most_calls'), - ): - core = _refusal_of(**options) - assert (type(core), core.code) == ( - StructuredDataError, - 'UNSUPPORTED_REQUEST', - ), options - assert core.details.get('rule') == rule, options + # The client sets no most on the entities, the calls or the context: + # entities the source does not hold are refused for that alone. core = _refusal_of(indices=list(range(1001))) assert (type(core), core.code) == (StructuredDataError, 'INVALID_REQUEST') diff --git a/packages/structured-data-models-client/tests/test_materialize_state.py b/packages/structured-data-models-client/tests/test_materialize_state.py index fc0588434..20f372cbe 100644 --- a/packages/structured-data-models-client/tests/test_materialize_state.py +++ b/packages/structured-data-models-client/tests/test_materialize_state.py @@ -602,8 +602,8 @@ def test_a_call_the_core_refuses_before_its_check_leaves_it_to_the_next() -> ( [query], connection, indices=[0, 1], - num_hops=7, - expected_error='UNSUPPORTED_REQUEST', + num_hops=0, + expected_error='INVALID_REQUEST', ) == [(0, 0)] assert _calls([query], connection, indices=[0, 1]) == [(6, 1)] other = PredictiveQuery(QUERY, schema) diff --git a/packages/structured-data-models-client/tests/test_payload_rules.py b/packages/structured-data-models-client/tests/test_payload_rules.py index 1f8e27b5e..f44b0fba3 100644 --- a/packages/structured-data-models-client/tests/test_payload_rules.py +++ b/packages/structured-data-models-client/tests/test_payload_rules.py @@ -82,17 +82,11 @@ def _size_case(length: int) -> dict[str, Any]: } -@pytest.mark.parametrize('length, accepted', [(275689, True), (275690, False)]) -def test_public_materialization_enforces_model_payload_byte_limit( - length: int, accepted: bool, monkeypatch: pytest.MonkeyPatch +@pytest.mark.parametrize('length', [275689, 275690]) +def test_public_materialization_holds_the_body_to_no_byte_limit( + length: int, monkeypatch: pytest.MonkeyPatch ) -> None: got, attachments = _on_the_core(_size_case(length), monkeypatch) - if not accepted: - assert got['outcome'] == 'refused', got - assert got['code'] == 'INVALID_REQUEST', got - assert '30MB' in got['message'], got - assert not attachments - return assert got['outcome'] == 'payload', got assert len(attachments) == 1 state = json.loads(attachments[0]) @@ -105,37 +99,13 @@ def test_public_materialization_enforces_model_payload_byte_limit( prefix = b'{"client_generated_keys":{"orders":"__node_id"},' assert attachments[0].startswith(prefix) assert model_bytes == b'{' + attachments[0][len(prefix) :] - assert len(model_bytes) <= 30 * 1024 * 1024 - - -@pytest.mark.parametrize('padding, accepted', [(5, True), (8, False)]) -def test_client_only_provenance_does_not_consume_model_payload_limit( - padding, accepted, monkeypatch -): - spec = _size_case(275689) - spec['setup'].append( - f"UPDATE users SET note=note||'{'a' * padding}' WHERE user_id=0" - ) - got, attachments = _on_the_core(spec, monkeypatch) - if accepted: - assert got['outcome'] == 'payload', got - state = bytes(attachments[0]) - prefix = b'{"client_generated_keys":{"orders":"__node_id"},' - assert state.startswith(prefix) - model_bytes = b'{' + state[len(prefix) :] - assert len(model_bytes) <= R.PAYLOAD_LIMIT < len(state) - else: - assert got['outcome'] == 'refused' - assert '30MB' in got['message'] REFUSAL_CODES = { 'base.regression.statistic-unknown': 'INVALID_REQUEST', 'base.binary.statistic': 'INVALID_REQUEST', 'base.regression.num-context-0': 'INVALID_REQUEST', - 'base.regression.num-context-10001': 'UNSUPPORTED_REQUEST', 'base.regression.entities-1001': 'INVALID_REQUEST', - 'star.tables-16': 'INVALID_REQUEST', 'empty.indices': 'INVALID_REQUEST', 'reserved.instance-id': 'INVALID_SCHEMA', 'reserved.anchor-time': 'INVALID_SCHEMA', diff --git a/packages/structured-data-models-client/tests/test_pql_for_tabular.py b/packages/structured-data-models-client/tests/test_pql_for_tabular.py index 5fbdd611b..564009d6a 100644 --- a/packages/structured-data-models-client/tests/test_pql_for_tabular.py +++ b/packages/structured-data-models-client/tests/test_pql_for_tabular.py @@ -174,10 +174,10 @@ def test_tabular_context_budget_limits_actual_rows(count): assert request.predict_rows == 1 -def test_tabular_context_budget_above_model_limit_is_refused(): - with pytest.raises(StructuredDataError) as error: - query().materialize(indices=[1], num_context_samples=10_001) - assert error.value.code == 'UNSUPPORTED_REQUEST' +def test_tabular_context_budget_past_10_000_is_taken(): + # The client sets no most: more than the rows there takes them all. + request = query().materialize(indices=[1], num_context_samples=10_001) + assert request.context_rows > 0 @pytest.mark.parametrize('count', [500, 10_001]) diff --git a/packages/structured-data-models-client/tests/test_predict_result.py b/packages/structured-data-models-client/tests/test_predict_result.py index 8e9bf5f5d..11a4af612 100644 --- a/packages/structured-data-models-client/tests/test_predict_result.py +++ b/packages/structured-data-models-client/tests/test_predict_result.py @@ -13,7 +13,6 @@ import importlib.util import json import math -import re import struct import sys from pathlib import Path @@ -40,20 +39,6 @@ def _recorder() -> Any: R = _recorder() CASES = [c for c in R.CASES if c['covers'] != R.BOUNDARY] -CASES.append( - { - 'name': 'size.one-past-the-limit', - 'covers': R.SIZE, - 'query': R.REGRESSION, - 'setup': [ - *R.shop(), - "CREATE OR REPLACE TABLE users AS SELECT *, repeat('a', 275690) AS note FROM users", - ], - 'materialize': {'indices': [0, 1], 'anchor_time': R.ANCHOR}, - 'predict': {}, - 'script': 'order:given', - } -) BOUNDARIES = [c for c in R.CASES if c['covers'] == R.BOUNDARY] @@ -90,7 +75,6 @@ def _decode(cell): 'prepare.not-a-request': 'INVALID_REQUEST', 'carry.longdouble-num-context': 'INVALID_REQUEST', 'carry.ndarray-target-transforms': 'UNSUPPORTED_REQUEST', - 'size.one-past-the-limit': 'INVALID_REQUEST', } VALID_NUMERIC_TEXT = { 'digit-separator', @@ -136,8 +120,6 @@ def capture(script, body): for key in ('field', 'reason'): if key in spec.get('core_outcome', {}): assert got['fields'][key] == spec['core_outcome'][key] - if name == 'size.one-past-the-limit': - assert re.search(r'30 ?MB|30 ?MiB|31,?457,?280', got['message']) return assert got['outcome'] == 'result', (name, got) assert calls and got['model'] == 'kumo-relational' diff --git a/packages/structured-data-models-client/tests/test_query_engine_boundary.py b/packages/structured-data-models-client/tests/test_query_engine_boundary.py index 5b4b94f27..61632e828 100644 --- a/packages/structured-data-models-client/tests/test_query_engine_boundary.py +++ b/packages/structured-data-models-client/tests/test_query_engine_boundary.py @@ -277,59 +277,41 @@ def test_a_rows_per_call_that_is_not_a_size_is_refused(given, text): assert 'a call scores a whole number of rows' in str(refused.value) -def test_a_batch_size_of_one_is_refused_for_the_contexts_it_would_hold( - monkeypatch, -): - """A context is gathered per call, so a small enough batch holds one per - entity however few entities there are.""" - from sdm_client.materializers import relational as materializer - - monkeypatch.setattr(materializer, 'MOST_CALLS', 3) +def test_a_batch_size_of_one_gathers_a_call_per_entity(): + """A context is gathered per call, and the client sets no most on the + calls: a batch of one is a call for each entity.""" with warnings.catch_warnings(): warnings.simplefilter('ignore') - with pytest.raises(StructuredDataError) as refused: - query().materialize( - indices=[5, 6, 7, 8, 9], - num_context_samples=20, - rows_per_call=1, - ) - assert refused.value.details['calls'] == 5 - assert '3 calls' in str(refused.value) - - -def test_a_population_past_the_ceiling_is_refused_before_the_engine_is_reached( - monkeypatch, -): - """Reaching the engine means building the graph and labelling every index, - which for a population far past the ceiling is minutes of work and the - memory with it before anything says no.""" - from sdm_client.materializers import relational as materializer - - monkeypatch.setattr(materializer, 'MOST_ENTITIES', 4) - with pytest.raises(StructuredDataError) as refused: - query().materialize(indices=list(range(5)), num_context_samples=20) - assert refused.value.code == 'UNSUPPORTED_REQUEST' - assert refused.value.details['entities'] == 5 + request = query().materialize( + indices=[5, 6, 7, 8, 9], + num_context_samples=20, + rows_per_call=1, + ) + assert len(request.payloads) == 5 -def test_more_calls_than_fit_in_memory_are_refused_before_they_are_built( - monkeypatch, -): - """The calls a population comes to is known only once the engine has said - how many entities it really holds, so this one is checked there, and still - before the batches themselves are built. - """ - from sdm_client.materializers import relational as materializer +def test_more_than_100_000_entities_are_gathered(): + """The client sets no most on the entities one materialize gathers.""" + from sdm_client import KumoRelational - monkeypatch.setattr(materializer, 'MOST_CALLS', 2) + count = 100_001 + frame = pd.DataFrame( + {'uid': range(count + 10), 'label': [*range(count), *[None] * 10]} + ) + users = Schema.from_data({'users': frame}, primary_keys={'users': 'uid'}) + users['users']['label'].stype = 'numerical' with warnings.catch_warnings(): warnings.simplefilter('ignore') - with pytest.raises(StructuredDataError) as refused: - query().materialize( - indices=[5, 6, 7, 8, 9], num_context_samples=20, rows_per_call=2 - ) - assert refused.value.code == 'UNSUPPORTED_REQUEST' - assert refused.value.details['calls'] == 3 + request = PredictiveQuery( + 'PREDICT users.label FOR EACH users.uid', users + ).materialize( + indices=list(range(count)), + model=KumoRelational(), + rows_per_call=50_001, + ) + assert [ + len(p['predict']['instance_table']['rows']) for p in request.payloads + ] == [50_001, 50_000] def test_a_call_that_fails_keeps_the_answers_already_paid_for(monkeypatch): @@ -708,22 +690,18 @@ def gathered_from(built: Schema) -> set[str]: return set(request.payloads[0]['schema']['related_tables']) -def test_a_schema_wider_than_the_cap_is_gathered_when_its_subgraph_is_not(): - """21 declared tables, 6 gathered, and the endpoint reads 15.""" - from sdm_client.models import RELATIONAL_LIMITS - +def test_a_schema_wider_than_fifteen_tables_is_gathered_as_its_subgraph(): + """21 declared tables, 6 gathered: what is sent is what the query reaches.""" built = star(satellites=20, joining=5) - assert len(built) > RELATIONAL_LIMITS['tables_max'] + assert len(built) > 15 assert len(gathered_from(built)) == 6 -def test_a_subgraph_wider_than_the_cap_is_still_refused(): - from sdm_client.models import RELATIONAL_LIMITS - - with pytest.raises(StructuredDataError) as error: - gathered_from(star(satellites=20, joining=20)) - assert str(RELATIONAL_LIMITS['tables_max']) in str(error.value) +def test_a_subgraph_wider_than_fifteen_tables_is_gathered_whole(): + """The client sets no most on the tables a request carries: a subgraph + of 21 is gathered whole.""" + assert len(gathered_from(star(satellites=20, joining=20))) == 21 # --- a table the request leaves out is said to be left out ------------------ @@ -1072,8 +1050,8 @@ def test_a_lone_table_is_not_told_which_was_taken(): ids=['an empty num_neighbors', 'num_hops of zero'], ) def test_both_spellings_of_no_hop_are_refused_alike(option, names): - """They are one request written two ways, and the endpoint reads between 1 - and 6 hops, so one slipping through to be taken literally was the defect.""" + """They are one request written two ways, and a request samples at least + one hop, so one slipping through to be taken literally was the defect.""" built = catalogue_schema() with pytest.raises(StructuredDataError, match='no hop at all') as raised: diff --git a/packages/structured-data-models-client/tests/test_tabular_direct_core.py b/packages/structured-data-models-client/tests/test_tabular_direct_core.py index aa02aef5b..ee75d90e5 100644 --- a/packages/structured-data-models-client/tests/test_tabular_direct_core.py +++ b/packages/structured-data-models-client/tests/test_tabular_direct_core.py @@ -392,9 +392,10 @@ def test_direct_context_limit_never_samples() -> None: scoring = pd.DataFrame({'feature': [30, 31]}) request = Request(context, scoring, target='target', task='classification') endpoint = Endpoint() - with pytest.raises(StructuredDataError, match='reads at most 10,000'): - client(endpoint).predict(request, model='kumo-tabular') - assert endpoint.calls == [] + # A direct context is sent as it was given, held to no size. + client(endpoint).predict(request, model='kumo-tabular') + (sent,) = endpoint.calls + assert len(sent['context']['instance_table']['rows']) == 10001 def test_target_container_guard_is_immediate() -> None: diff --git a/packages/structured-data-models-client/tests/test_tabular_pql_counts.py b/packages/structured-data-models-client/tests/test_tabular_pql_counts.py index 49ae3f5b3..58c3a68ae 100644 --- a/packages/structured-data-models-client/tests/test_tabular_pql_counts.py +++ b/packages/structured-data-models-client/tests/test_tabular_pql_counts.py @@ -67,9 +67,8 @@ def test_public_count_task_journey(monkeypatch, route, name): ['endpoint', expected_count], ['predicted'], ] - if name == 'count_owner': - assert events[:-3] == [['count_gt', actual['cap']]] - elif name.startswith('task_') or name in ( + # The count is the core's to weigh: the host compares it with no cap. + if name.startswith('task_') or name in ( 'over_default', 'warning_record', ): diff --git a/packages/structured-data-models-client/tests/test_the_predict_route.py b/packages/structured-data-models-client/tests/test_the_predict_route.py index 6392f9476..ba5892792 100644 --- a/packages/structured-data-models-client/tests/test_the_predict_route.py +++ b/packages/structured-data-models-client/tests/test_the_predict_route.py @@ -761,21 +761,13 @@ def recording(self: Any, adapter: Any, body: bytes) -> Any: return written, received, refused.value -def test_the_bytes_sent_are_the_core_s_and_held_to_the_limit( +def test_the_bytes_sent_are_the_core_s_at_any_size( monkeypatch: pytest.MonkeyPatch, ) -> None: - # Register PD-2: the HTTP transport sends the - # core's call as the core wrote it, so the bytes the endpoint receives - # are the bytes the core counted against the limit, characters past - # ASCII as their own bytes, never json.dumps' escapes. At the limit's - # edge the call is sent, at most the limit; one character past it, - # nothing is sent. Since the reference's 26ecdd28 the call - # leaves out the engine's inference config, which the payload holds, - # so the payload is the larger and meets the limit first: the edge is - # the payload's, which materialize names in its refusal, and one past - # it materialize refuses (the call's own refusal, past the limit with - # the payload within it, is sdm-core's - # a_call_past_the_limit_is_refused_before_it_is_sent). + # Register PD-2: the HTTP transport sends the core's call as the core + # wrote it, characters past ASCII as their own bytes, never json.dumps' + # escapes; and the client holds a call to no size of its own, so one + # past the 30 MiB the reference refused is sent. limit = 30 * 1024 * 1024 lengths = [] for emoji, ascii in ((0, 0), (1, 0), (0, 1)): @@ -784,39 +776,17 @@ def test_the_bytes_sent_are_the_core_s_and_held_to_the_limit( ) assert written == received lengths.append(len(received[0])) - base, wide, narrow = ( - lengths[0], - lengths[1] - lengths[0], - lengths[2] - lengths[0], - ) - assert wide % 4 == 0 and narrow == 1 - emoji = (limit - base) // wide - ascii = (limit - base - emoji * wide) // narrow - # The call's edge is past the payload's: materialize refuses it, naming - # the payload's size, and the payload's edge is that much nearer. - with pytest.raises(StructuredDataError) as over: - _emoji_request(monkeypatch, emoji, ascii) - details = over.value.details - assert over.value.code == 'INVALID_REQUEST' - assert details['field'] == 'payload' and details['limit'] == limit - excess = details['bytes'] - limit - assert 0 < excess < wide * 64 - room = emoji * wide + ascii * narrow - excess - emoji = room // wide - ascii = (room - emoji * wide) // narrow + base, wide = lengths[0], lengths[1] - lengths[0] + assert wide % 4 == 0 and lengths[2] - lengths[0] == 1 + emoji = (limit - base) // wide + 1 written, received, refused = _sent( - monkeypatch, _emoji_request(monkeypatch, emoji, ascii) + monkeypatch, _emoji_request(monkeypatch, emoji, 0) ) assert refused.code == 'RECORDED' assert written == received - assert len(received[0]) == base + emoji * wide + ascii * narrow <= limit + assert len(received[0]) == base + emoji * wide > limit assert b'\\ud83d' not in received[0] assert '\U0001f600'.encode() in received[0] - with pytest.raises(StructuredDataError) as past: - _emoji_request(monkeypatch, emoji, ascii + 1) - assert past.value.code == 'INVALID_REQUEST' - assert past.value.details['field'] == 'payload' - assert past.value.details['bytes'] == limit + 1 def test_embeddings_are_the_old_route_s_on_the_core( diff --git a/packages/structured-data-models-client/tests/test_wording.py b/packages/structured-data-models-client/tests/test_wording.py index 12ac5eef7..2ca7c8b3e 100644 --- a/packages/structured-data-models-client/tests/test_wording.py +++ b/packages/structured-data-models-client/tests/test_wording.py @@ -515,16 +515,10 @@ def _users() -> Schema: def test_the_context_size_refused_is_named_as_the_caller_gave_it() -> None: # The old client's words, with the value as given, however large - # (review r1, P1-2 and P1-3). + # (review r1, P1-2 and P1-3). No size past one is refused. query = PredictiveQuery( 'PREDICT COUNT(orders.*, 0, 30, days) FOR EACH users.user_id', _users() ) - with pytest.raises(StructuredDataError) as past: - query.materialize(indices=[1], num_context_samples=10_001) - assert str(past.value).split('] ', 1)[1] == ( - 'num_context_samples is 10,001, and the endpoint accepts at most ' - '10,000 context rows' - ) with pytest.raises(StructuredDataError) as below: query.materialize(indices=[1], num_context_samples=-(10**100)) assert str(below.value).split('] ', 1)[1] == ( diff --git a/rust/crates/sdm-contract/schema/contract.lock b/rust/crates/sdm-contract/schema/contract.lock index 7e5638785..399b9e077 100644 --- a/rust/crates/sdm-contract/schema/contract.lock +++ b/rust/crates/sdm-contract/schema/contract.lock @@ -1,2 +1,2 @@ # Current sdm-contract schema; regenerate with schema_lock.rs. -72 sha256:9bb2ddbb1b5eea8a8a7359b0c1aef58c510db5b9bbe6a7856c2860d06d8a44f2 sdm-contract-72.json +74 sha256:1a3bd8acf2315158793b44a95e86a747992a351b3c4597d63230d704e27e5d28 sdm-contract-74.json diff --git a/rust/crates/sdm-contract/schema/sdm-contract-72.json b/rust/crates/sdm-contract/schema/sdm-contract-74.json similarity index 99% rename from rust/crates/sdm-contract/schema/sdm-contract-72.json rename to rust/crates/sdm-contract/schema/sdm-contract-74.json index ced88f19e..e8f8c3434 100644 --- a/rust/crates/sdm-contract/schema/sdm-contract-72.json +++ b/rust/crates/sdm-contract/schema/sdm-contract-74.json @@ -1,5 +1,5 @@ { - "$id": "sdm-contract/72", + "$id": "sdm-contract/74", "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "ControlMessage", "description": "Every control message that crosses between a host and the core.", @@ -306,12 +306,6 @@ "DirectValue.select_tabular_rows": { "$ref": "#/$defs/SelectedTabularRows" }, - "CheckTabularCap.input": { - "$ref": "#/$defs/CheckTabularCap" - }, - "DirectValue.check_tabular_cap": { - "$ref": "#/$defs/CheckedTabularCap" - }, "ObserveTabularMembership.input": { "$ref": "#/$defs/ObserveTabularMembership" }, @@ -699,8 +693,6 @@ "tabular_arrow_session", "SelectTabularRows.input", "DirectValue.select_tabular_rows", - "CheckTabularCap.input", - "DirectValue.check_tabular_cap", "ObserveTabularMembership.input", "DirectValue.observe_tabular_membership", "DecideTabularTask.input", @@ -3865,35 +3857,9 @@ "type": "string", "enum": [ "zero", - "above_limit", "above_population" ] }, - "CheckTabularCap": { - "description": "Reached native comparison against the model cap, before frame length reads.", - "type": "object", - "properties": { - "over_limit": { - "type": "boolean" - } - }, - "additionalProperties": false, - "required": [ - "over_limit" - ] - }, - "CheckedTabularCap": { - "type": "object", - "properties": { - "accepted": { - "type": "boolean" - } - }, - "additionalProperties": false, - "required": [ - "accepted" - ] - }, "ObserveTabularMembership": { "type": "object", "properties": { @@ -7993,22 +7959,6 @@ ], "format": "uint32", "minimum": 0 - }, - "most_entities": { - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0 - }, - "most_calls": { - "type": [ - "integer", - "null" - ], - "format": "uint32", - "minimum": 0 } }, "additionalProperties": false, @@ -13763,24 +13713,6 @@ "input" ] }, - { - "description": "An input-sized direct value, carried as typed JSON bytes.", - "type": "object", - "properties": { - "input": { - "$ref": "#/$defs/AttachmentId" - }, - "op": { - "type": "string", - "const": "check_tabular_cap" - } - }, - "additionalProperties": false, - "required": [ - "op", - "input" - ] - }, { "description": "An input-sized direct value, carried as typed JSON bytes.", "type": "object", @@ -14555,24 +14487,6 @@ "format": "uint32", "minimum": 0 }, - "most_entities": { - "description": "The most entities one `materialize` gathers, across the calls it is\nasked in, which the host lets its caller set (`main`'s\n`MOST_ENTITIES`); 100,000 where it names none (design choice 1,\nmulti-call `predict`, read which asks a request of more\nrows than one call scores in several calls; until then the core\nrefuses more than one call's rows, a lower bound than either).", - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0 - }, - "most_calls": { - "description": "The most model calls one request is asked in (`main`'s\n`MOST_CALLS`); 100 where the host names none (read as\n`most_entities`).", - "type": [ - "integer", - "null" - ], - "format": "uint32", - "minimum": 0 - }, "sampler_state": { "description": "The sampler state the materializer's last run left, which the host\nhands back as it took it; none for a materializer's\nfirst run.", "anyOf": [ @@ -17530,7 +17444,6 @@ "direct_scored", "direct_target_missing", "direct_target_scored", - "direct_context_limit", "tabular_missing_row_index", "direct_multilabel", "direct_relational_frames", @@ -17686,7 +17599,6 @@ "undeclared", "seed_past_range", "big_integer_past_type", - "lag_past_payload", "date_literal_packed", "local_zone_unread", "clock_past_years", @@ -17739,7 +17651,6 @@ "model_lacks_task", "temporal_link_unserved", "model_lacks_outputs", - "context_past_model", "no_context_rows", "too_many_classes", "one_class_column", @@ -17758,9 +17669,6 @@ "explanation_fast_mode", "options_unread", "options_unread_statistic", - "payload_smaller_calls", - "payload_no_smaller_call", - "call_past_endpoint", "outputs_none", "not_finite", "past_int64", @@ -17771,7 +17679,6 @@ "lag_past_times", "num_context_samples_not_whole", "num_context_samples_below_one", - "num_context_samples_past_most", "num_hops_not_whole", "num_hops_none", "random_seed_not_whole", @@ -17794,10 +17701,9 @@ "excluded_not_a_sequence", "statistic_unknown", "statistic_not_a_regression", + "sampling_hops_limit", "no_hop_num_hops", "no_hop_num_neighbors", - "hops_past_endpoint", - "hops_past_endpoint_uncounted", "inference_run_mode_invalid", "inference_config_not_an_object", "inference_option_unknown", @@ -17836,7 +17742,6 @@ "entity_table_empty", "entity_key_missing", "target_not_a_feature", - "context_past_rows", "held_by_several_rows_one", "held_by_several_rows", "held_by_several_rows_many", @@ -17845,7 +17750,6 @@ "frame_key_missing_parts", "frame_no_valid_rows", "not_in_table", - "subgraph_past_tables", "unresolved", "anchor_not_a_time", "anchor_before_data", @@ -17862,9 +17766,6 @@ "no_entity_passed_several", "anchor_too_late_several", "forecast_top_k", - "most_entities", - "most_entities_parts", - "most_calls", "not_yet_materialize", "missing_index_table", "missing_index_tables", diff --git a/rust/crates/sdm-contract/src/error.rs b/rust/crates/sdm-contract/src/error.rs index 99a57cc40..a742a46cc 100644 --- a/rust/crates/sdm-contract/src/error.rs +++ b/rust/crates/sdm-contract/src/error.rs @@ -787,7 +787,6 @@ sentences! { DirectScored = "direct_scored", E::InvalidRequest; DirectTargetMissing = "direct_target_missing", E::InvalidRequest; DirectTargetScored = "direct_target_scored", E::InvalidRequest; - DirectContextLimit = "direct_context_limit", E::UnsupportedRequest; TabularMissingRowIndex = "tabular_missing_row_index", E::InvalidResponse; DirectMultilabel = "direct_multilabel", E::UnsupportedRequest; DirectRelationalFrames = "direct_relational_frames", E::UnsupportedRequest; @@ -943,7 +942,6 @@ sentences! { Undeclared = "undeclared", E::UnsupportedRequest; SeedPastRange = "seed_past_range", E::InvalidRequest; BigIntegerPastType = "big_integer_past_type", E::ValueOutOfRange; - LagPastPayload = "lag_past_payload", E::InvalidRequest; DateLiteralPacked = "date_literal_packed", E::InvalidRequest, rule "date_literal_packed"; LocalZoneUnread = "local_zone_unread", E::InvalidRequest; ClockPastYears = "clock_past_years", E::InvalidRequest; @@ -996,7 +994,6 @@ sentences! { ModelLacksTask = "model_lacks_task", E::UnsupportedRequest; TemporalLinkUnserved = "temporal_link_unserved", E::UnsupportedRequest, rule "temporal_link_prediction"; ModelLacksOutputs = "model_lacks_outputs", E::UnsupportedRequest; - ContextPastModel = "context_past_model", E::UnsupportedRequest; NoContextRows = "no_context_rows", E::UnsupportedRequest; TooManyClasses = "too_many_classes", E::UnsupportedRequest; OneClassColumn = "one_class_column", E::UnsupportedRequest; @@ -1015,9 +1012,6 @@ sentences! { ExplanationFastMode = "explanation_fast_mode", E::UnsupportedRequest; OptionsUnread = "options_unread", E::UnsupportedRequest; OptionsUnreadStatistic = "options_unread_statistic", E::UnsupportedRequest; - PayloadSmallerCalls = "payload_smaller_calls", E::InvalidRequest; - PayloadNoSmallerCall = "payload_no_smaller_call", E::InvalidRequest; - CallPastEndpoint = "call_past_endpoint", E::InvalidRequest; OutputsNone = "outputs_none", E::InvalidRequest; NotFinite = "not_finite", E::InvalidRequest; PastInt64 = "past_int64", E::InvalidRequest; @@ -1028,7 +1022,6 @@ sentences! { LagPastTimes = "lag_past_times", E::ValueOutOfRange; NumContextSamplesNotWhole = "num_context_samples_not_whole", E::InvalidRequest; NumContextSamplesBelowOne = "num_context_samples_below_one", E::InvalidRequest; - NumContextSamplesPastMost = "num_context_samples_past_most", E::UnsupportedRequest; NumHopsNotWhole = "num_hops_not_whole", E::InvalidRequest; NumHopsNone = "num_hops_none", E::InvalidRequest; RandomSeedNotWhole = "random_seed_not_whole", E::InvalidRequest; @@ -1051,10 +1044,9 @@ sentences! { ExcludedNotASequence = "excluded_not_a_sequence", E::InvalidRequest; StatisticUnknown = "statistic_unknown", E::InvalidRequest; StatisticNotARegression = "statistic_not_a_regression", E::InvalidRequest; + SamplingHopsLimit = "sampling_hops_limit", E::UnsupportedRequest; NoHopNumHops = "no_hop_num_hops", E::InvalidRequest; NoHopNumNeighbors = "no_hop_num_neighbors", E::InvalidRequest; - HopsPastEndpoint = "hops_past_endpoint", E::UnsupportedRequest; - HopsPastEndpointUncounted = "hops_past_endpoint_uncounted", E::UnsupportedRequest; InferenceRunModeInvalid = "inference_run_mode_invalid", E::InvalidRequest; InferenceConfigNotAnObject = "inference_config_not_an_object", E::InvalidRequest; InferenceOptionUnknown = "inference_option_unknown", E::InvalidRequest; @@ -1093,7 +1085,6 @@ sentences! { EntityTableEmpty = "entity_table_empty", E::InvalidRequest; EntityKeyMissing = "entity_key_missing", E::InvalidRequest; TargetNotAFeature = "target_not_a_feature", E::InvalidRequest; - ContextPastRows = "context_past_rows", E::InvalidRequest; HeldBySeveralRowsOne = "held_by_several_rows_one", E::InvalidRequest; HeldBySeveralRows = "held_by_several_rows", E::InvalidRequest; HeldBySeveralRowsMany = "held_by_several_rows_many", E::InvalidRequest; @@ -1102,7 +1093,6 @@ sentences! { FrameKeyMissingParts = "frame_key_missing_parts", E::InvalidRequest; FrameNoValidRows = "frame_no_valid_rows", E::InvalidRequest; NotInTable = "not_in_table", E::InvalidRequest; - SubgraphPastTables = "subgraph_past_tables", E::InvalidRequest; Unresolved = "unresolved", E::InvalidRequest; AnchorNotATime = "anchor_not_a_time", E::InvalidRequest; AnchorBeforeData = "anchor_before_data", E::InvalidRequest; @@ -1119,9 +1109,6 @@ sentences! { NoEntityPassedSeveral = "no_entity_passed_several", E::InvalidRequest; AnchorTooLateSeveral = "anchor_too_late_several", E::InvalidRequest; ForecastTopK = "forecast_top_k", E::InvalidRequest, rule "forecast_top_k"; - MostEntities = "most_entities", E::UnsupportedRequest, rule "most_entities"; - MostEntitiesParts = "most_entities_parts", E::UnsupportedRequest, rule "most_entities"; - MostCalls = "most_calls", E::UnsupportedRequest, rule "most_calls"; NotYetMaterialize = "not_yet_materialize", E::UnsupportedRequest; MissingIndexTable = "missing_index_table", W::MissingIndices; MissingIndexTables = "missing_index_tables", W::MissingIndices; diff --git a/rust/crates/sdm-contract/src/frames.rs b/rust/crates/sdm-contract/src/frames.rs index a84df1c27..9e2c4c48f 100644 --- a/rust/crates/sdm-contract/src/frames.rs +++ b/rust/crates/sdm-contract/src/frames.rs @@ -83,8 +83,6 @@ pub struct FrameCall { #[serde(default)] pub options: Vec, pub most_parts: Option, - pub most_entities: Option, - pub most_calls: Option, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] diff --git a/rust/crates/sdm-contract/src/lib.rs b/rust/crates/sdm-contract/src/lib.rs index 47893f2cb..5ce953172 100644 --- a/rust/crates/sdm-contract/src/lib.rs +++ b/rust/crates/sdm-contract/src/lib.rs @@ -56,7 +56,7 @@ pub use scalar::Scalar; pub use types::{ColumnType, Field, Unit}; /// The contract version this build speaks. -pub const CONTRACT_VERSION: u32 = 72; +pub const CONTRACT_VERSION: u32 = 74; /// The JSON Schema of [`ControlMessage`], as committed: pretty-printed, with /// a trailing newline. Its `$defs` hold [`ops::Attachments`] too, the JSON diff --git a/rust/crates/sdm-contract/src/ops.rs b/rust/crates/sdm-contract/src/ops.rs index edf8ff1ae..8a5be39cd 100644 --- a/rust/crates/sdm-contract/src/ops.rs +++ b/rust/crates/sdm-contract/src/ops.rs @@ -68,7 +68,6 @@ pub enum Operation { DecideTabularTask(crate::direct::DirectInput), OrderSampledTabularRows(crate::direct::DirectInput), SelectTabularRows(crate::direct::DirectInput), - CheckTabularCap(crate::direct::DirectInput), CheckDirectShape(crate::direct::DirectInput), CheckDirectCell(crate::direct::DirectInput), CheckColumn(crate::direct::DirectInput), @@ -160,7 +159,6 @@ impl Operation { Operation::DecideTabularTask(_) => "decide_tabular_task", Operation::OrderSampledTabularRows(_) => "order_sampled_tabular_rows", Operation::SelectTabularRows(_) => "select_tabular_rows", - Operation::CheckTabularCap(_) => "check_tabular_cap", Operation::CheckDirectShape(_) => "check_direct_shape", Operation::CheckDirectCell(_) => "check_direct_cell", Operation::CheckColumn(_) => "check_column", @@ -332,7 +330,6 @@ impl Operation { | Operation::DecideTabularTask(v) | Operation::OrderSampledTabularRows(v) | Operation::SelectTabularRows(v) - | Operation::CheckTabularCap(v) | Operation::CheckDirectShape(v) | Operation::CheckDirectCell(v) | Operation::FeatureImportance(v) @@ -1358,19 +1355,6 @@ pub struct Materialize { /// `too_many_parts`. #[serde(default, skip_serializing_if = "Option::is_none")] pub most_parts: Option, - /// The most entities one `materialize` gathers, across the calls it is - /// asked in, which the host lets its caller set (`main`'s - /// `MOST_ENTITIES`); 100,000 where it names none (design choice 1, - /// multi-call `predict`, read which asks a request of more - /// rows than one call scores in several calls; until then the core - /// refuses more than one call's rows, a lower bound than either). - #[serde(default, skip_serializing_if = "Option::is_none")] - pub most_entities: Option, - /// The most model calls one request is asked in (`main`'s - /// `MOST_CALLS`); 100 where the host names none (read as - /// `most_entities`). - #[serde(default, skip_serializing_if = "Option::is_none")] - pub most_calls: Option, /// The sampler state the materializer's last run left, which the host /// hands back as it took it; none for a materializer's /// first run. @@ -1980,10 +1964,6 @@ pub struct Attachments { pub select_tabular_rows_input: crate::tabular::SelectTabularRows, #[schemars(rename = "DirectValue.select_tabular_rows")] pub select_tabular_rows_output: crate::tabular::SelectedTabularRows, - #[schemars(rename = "CheckTabularCap.input")] - pub check_tabular_cap_input: crate::tabular::CheckTabularCap, - #[schemars(rename = "DirectValue.check_tabular_cap")] - pub check_tabular_cap_output: crate::tabular::CheckedTabularCap, #[schemars(rename = "ObserveTabularMembership.input")] pub observe_tabular_membership_input: crate::tabular::ObserveTabularMembership, #[schemars(rename = "DirectValue.observe_tabular_membership")] diff --git a/rust/crates/sdm-contract/src/tabular.rs b/rust/crates/sdm-contract/src/tabular.rs index 443c1afad..5d96a0fc0 100644 --- a/rust/crates/sdm-contract/src/tabular.rs +++ b/rust/crates/sdm-contract/src/tabular.rs @@ -64,7 +64,6 @@ pub struct DecideTabularContext { #[serde(rename_all = "snake_case")] pub enum TabularCountError { Zero, - AboveLimit, AbovePopulation, } @@ -472,19 +471,6 @@ pub enum TabularOrderError { TemporalYearOutOfRange, } -/// Reached native comparison against the model cap, before frame length reads. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[serde(deny_unknown_fields)] -pub struct CheckTabularCap { - pub over_limit: bool, -} - -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] -#[serde(deny_unknown_fields)] -pub struct CheckedTabularCap { - pub accepted: bool, -} - /// One ordinary selection composition. Only proven-passive native producers /// may supply the complete population before earlier semantic guards finish. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] diff --git a/rust/crates/sdm-contract/src/wording.rs b/rust/crates/sdm-contract/src/wording.rs index 63b6f93b8..3e9a24893 100644 --- a/rust/crates/sdm-contract/src/wording.rs +++ b/rust/crates/sdm-contract/src/wording.rs @@ -201,7 +201,6 @@ advice! { EmptyRequest = "empty_request", []; GiveAHop = "give_a_hop", []; KeepOneLink = "keep_one_link", ["source_table", "target_table", "others"]; - MaterializeCall = "materialize_call", []; MissingTime = "missing_time", []; NameCandidates = "name_candidates", ["column"]; NamePrimaryKey = "name_primary_key", ["table"]; @@ -214,7 +213,6 @@ advice! { ResultFrame = "result_frame", []; SetPrimaryKey = "set_primary_key", ["target_table", "target_column"]; SkipKeyCheck = "skip_key_check", []; - SmallerCalls = "smaller_calls", []; TrustExpressions = "trust_expressions", []; } @@ -340,9 +338,6 @@ pub fn template(sentence: Sentence) -> Template { S::DirectTargetScored => said( r#"predict carries the target column {target!r}. Those are the rows whose answer is being asked for, so the column has to be absent; drop it with predict.drop(columns=[{target!r}])"#, ), - S::DirectContextLimit => said( - r#"this request carries {context_rows:,} context rows and {model} reads at most {context_rows_max:,}. A request built directly is sent as it was given, so choose the rows you want as context, or gather it with materialize(), which keeps the context under the cap and says how"#, - ), S::TabularMissingRowIndex => said( r#"kumo-tabular returned a response that does not match the contract: PredictionItem response is missing required field 'row_index'"#, ), @@ -747,9 +742,6 @@ pub fn template(sentence: Sentence) -> Template { S::BigIntegerPastType => said( r#"column {column!r} holds a value that {admitted_type}, the type it was described as, cannot hold"#, ), - S::LagPastPayload => said( - r#"the {lag_timesteps:,} past steps lag_timesteps asks for make the request larger than the {limit:,} bytes the endpoint takes; ask for fewer steps"#, - ), S::DateLiteralPacked => said( r#"{query!r} is not a query a relational model can answer: {literal} is not a valid instance of time"#, ), @@ -888,9 +880,6 @@ pub fn template(sentence: Sentence) -> Template { S::ModelLacksOutputs => said( r#"{model} does not produce {unsupported_outputs!r}; it produces {supported_outputs!r}"#, ), - S::ContextPastModel => said( - r#"this request carries {context_rows:,} context rows and {model} reads at most {context_rows_max:,}. A request built directly is sent as it was given, so choose the rows you want as context, or gather it with {advice:materialize_call()}, which keeps the context under the cap and says how"#, - ), S::NoContextRows => said( r#"no context rows are left: every row that could be context is also being scored, and a row carrying the answer being asked for is not sent as context. Score fewer rows, so that the rest are there to learn from"#, ), @@ -942,15 +931,6 @@ pub fn template(sentence: Sentence) -> Template { S::OptionsUnreadStatistic => said( r#"{model} does not read inference option(s) {unsupported!r}; drop them from inference_config to send the request without them. The keys this client forwards are {forwarded!r}, and the endpoint decides for itself whether it serves the value given for one. A regression's statistic is chosen with {advice:choose_statistic()} instead: 'median', the default, or 'mean'"#, ), - S::PayloadSmallerCalls => said( - r#"Context size exceeds the 30MB limit. This call is {bytes:,} bytes, and the endpoint takes at most {limit:,}. What comes down is one of three. For an ordinary question it is the call: {advice:smaller_calls()} below the {rows_per_call:,} this one holds asks for the same entities in more and smaller calls. Where the context is itself over the limit, no call is small enough, and it is num_context_samples, num_neighbors or the columns the graph carries. For a ranking or a forecast, which is one call per candidate or step and is never batched, it is the entities."#, - ), - S::PayloadNoSmallerCall => said( - r#"Context size exceeds the 30MB limit. This call is {bytes:,} bytes, and the endpoint takes at most {limit:,}. A call already scores one row, so there is no smaller one to ask for: what comes down is num_context_samples, num_neighbors or the columns the graph carries."#, - ), - S::CallPastEndpoint => said( - r#"the request is {bytes:,} bytes and the endpoint takes at most {limit:,} bytes; reduce the number of tables in the graph, their columns, the neighbourhood sampled or the context gathered (num_context_samples)"#, - ), S::OutputsNone => said(r#"outputs must name at least one field"#), S::NotFinite => said( r#"encountered a non-finite value ({value}); NIM requests must contain finite numbers or nulls"#, @@ -979,9 +959,6 @@ pub fn template(sentence: Sentence) -> Template { S::NumContextSamplesBelowOne => said( r#"num_context_samples must be at least 1; a model predicts from labelled examples, and {given!S} leaves it none"#, ), - S::NumContextSamplesPastMost => said( - r#"num_context_samples is {given!I:,}, and the endpoint accepts at most {limit:,} context rows"#, - ), S::NumHopsNotWhole => said(r#"num_hops must be a whole number, got {given!N} {given!G}"#), S::NumHopsNone => said(r#"num_hops must be a whole number, got {advice:nothing()}"#), S::RandomSeedNotWhole => said(r#"random_seed must be a whole number"#), @@ -1035,18 +1012,13 @@ pub fn template(sentence: Sentence) -> Template { S::StatisticNotARegression => said( r#"prediction_statistic applies only to a regression, and this question is a {task}; ask it without prediction_statistic"#, ), + S::SamplingHopsLimit => said("sampling supports at most {limit} hops; reduce {field}"), S::NoHopNumHops => said( - r#"num_hops is {hops}, which asks for no hop at all, and the endpoint reads between 1 and {limit}. A request that crosses no relationship is a single-table one: give a hop, such as {advice:give_a_hop()}, or ask it of kumo-tabular"#, + r#"num_hops is {hops}, which asks for no hop at all, and a request samples at least 1. A request that crosses no relationship is a single-table one: give a hop, such as {advice:give_a_hop()}, or ask it of kumo-tabular"#, ), S::NoHopNumNeighbors => said( - r#"num_neighbors is empty, which asks for no hop at all, and the endpoint reads between 1 and {limit}. A request that crosses no relationship is a single-table one: give a hop, such as {advice:give_a_hop()}, or ask it of kumo-tabular"#, + r#"num_neighbors is empty, which asks for no hop at all, and a request samples at least 1. A request that crosses no relationship is a single-table one: give a hop, such as {advice:give_a_hop()}, or ask it of kumo-tabular"#, ), - S::HopsPastEndpoint => { - said(r#"this request samples {hops} hops and the endpoint reads at most {limit}"#) - } - S::HopsPastEndpointUncounted => { - said(r#"this request samples more hops than the endpoint reads, at most {limit}"#) - } S::InferenceRunModeInvalid => { said("inference run_mode is text of at most 1024 characters, or null") } @@ -1153,7 +1125,6 @@ pub fn template(sentence: Sentence) -> Template { S::TargetNotAFeature => { said(r#"the column the query predicts is not one of the features of the entity table"#) } - S::ContextPastRows => said(r#"the context holds more rows than a request takes"#), S::HeldBySeveralRowsOne => said( r#"Cannot score {keys[0]!r}: more than one row of table '{table}' holds this value of '{key}', so which row is meant would be a guess. The source does not enforce the key; keep one row per value, or key the table on columns that identify a row."#, ), @@ -1173,9 +1144,6 @@ pub fn template(sentence: Sentence) -> Template { said("Found no valid rows in table '{table}'; supply valid non-missing {requirements}.") } S::NotInTable => said(r#""The primary keys {keys!r} do not exist in the '{table}' table""#), - S::SubgraphPastTables => said( - r#"the request's subgraph carries {tables:,} tables, and the endpoint reads at most {limit:,}"#, - ), S::Unresolved => { said(r#"{query!r} is not a query a relational model can answer: {reasons!R}"#) } @@ -1222,15 +1190,6 @@ pub fn template(sentence: Sentence) -> Template { S::ForecastTopK => said( r#"top_k is how many candidates a ranking keeps, and a forecast ranks nothing; it gives back one value per step"#, ), - S::MostEntities => said( - r#"{entities:,} entities is past the {limit:,} one {advice:materialize_call()} will hold at once, since every batch is built, with its own context, before any is sent; ask about fewer entities at a time"#, - ), - S::MostEntitiesParts => said( - r#"{entities:,} entities gathered {gathered_times:,} times over, {total:,} in all, is past the {limit:,} one {advice:materialize_call()} will hold at once, since every batch is built, with its own context, before any is sent; ask about fewer entities at a time"#, - ), - S::MostCalls => said( - r#"{entities:,} entities are gathered as {calls:,} calls of {rows_per_call:,}, and every one is built, with its own context, before any is sent. That is past the {limit:,} calls this will hold at once; ask about fewer entities at a time"#, - ), S::NotYetMaterialize => said( r#"materializing this request needs the {rule!r} rule, which is not one this client's core supports yet"#, ), diff --git a/rust/crates/sdm-contract/tests/corpus/mod.rs b/rust/crates/sdm-contract/tests/corpus/mod.rs index 79e7f9793..ee94a7a76 100644 --- a/rust/crates/sdm-contract/tests/corpus/mod.rs +++ b/rust/crates/sdm-contract/tests/corpus/mod.rs @@ -151,8 +151,6 @@ pub fn messages() -> Vec { values: None, options: vec!["num_neighbors".into()], most_parts: None, - most_entities: None, - most_calls: None, candidates: None, sampler_state: Some(SamplerState { version: 1, diff --git a/rust/crates/sdm-contract/tests/schema_lock.rs b/rust/crates/sdm-contract/tests/schema_lock.rs index bbe065843..4daaa96af 100644 --- a/rust/crates/sdm-contract/tests/schema_lock.rs +++ b/rust/crates/sdm-contract/tests/schema_lock.rs @@ -552,11 +552,6 @@ const JSON: &[(&str, &str)] = &[ "OperationResult/direct_value.value", "DirectValue.select_tabular_rows", ), - ("Operation/check_tabular_cap.input", "CheckTabularCap.input"), - ( - "OperationResult/direct_value.value", - "DirectValue.check_tabular_cap", - ), ( "Operation/observe_tabular_membership.input", "ObserveTabularMembership.input", diff --git a/rust/crates/sdm-contract/tests/wording.rs b/rust/crates/sdm-contract/tests/wording.rs index 0baf8070f..bc0113cec 100644 --- a/rust/crates/sdm-contract/tests/wording.rs +++ b/rust/crates/sdm-contract/tests/wording.rs @@ -377,7 +377,6 @@ fn the_sentences_the_hosts_choose_between_today_are_the_core_s() { Sentence::TimeColumnsRefusedEmpty, ), (Sentence::KeyNotNames, Sentence::KeyNotNamesGiven), - (Sentence::MostEntities, Sentence::MostEntitiesParts), (Sentence::BatchedPartForecast, Sentence::BatchedPartRanking), ( Sentence::CandidatesUnscoredOne, diff --git a/rust/crates/sdm-core/src/dispatch.rs b/rust/crates/sdm-core/src/dispatch.rs index 04aeffe69..dbce2b3b4 100644 --- a/rust/crates/sdm-core/src/dispatch.rs +++ b/rust/crates/sdm-core/src/dispatch.rs @@ -324,13 +324,6 @@ pub fn start( crate::direct::value(&asker, &crate::tabular_selection::select(input)?) }) } - Operation::CheckTabularCap(request) => { - let input: sdm_contract::tabular::CheckTabularCap = - take_json(&mut attachments, request.input)?; - Run::new(move |asker| async move { - crate::direct::value(&asker, &sdm_request::tabular::check_materialized_cap(input)) - }) - } Operation::CheckDirectShape(request) => { let input: sdm_contract::direct::DirectShape = take_json(&mut attachments, request.input)?; @@ -786,8 +779,6 @@ pub(crate) fn materialize( values, options: request.options, most_parts: request.most_parts, - most_entities: request.most_entities, - most_calls: request.most_calls, facts, zones: Arc::clone(&zones), #[cfg(feature = "test-ops")] diff --git a/rust/crates/sdm-core/src/frame_session.rs b/rust/crates/sdm-core/src/frame_session.rs index 2b0051767..0103f0226 100644 --- a/rust/crates/sdm-core/src/frame_session.rs +++ b/rust/crates/sdm-core/src/frame_session.rs @@ -64,11 +64,7 @@ pub(crate) async fn call( body: Value, ) -> Result { match asker - .call_model( - endpoint, - "application/json".into(), - predict::call_bytes(&body)?, - ) + .call_model(endpoint, "application/json".into(), body.to_bytes()) .await { Reply::Model(ModelResult::Response { status, body, .. }) diff --git a/rust/crates/sdm-core/src/lag.rs b/rust/crates/sdm-core/src/lag.rs index 55812a9e5..715e7534c 100644 --- a/rust/crates/sdm-core/src/lag.rs +++ b/rust/crates/sdm-core/src/lag.rs @@ -34,23 +34,15 @@ //! than their own; the core puts each on its own row ( fix 1, a //! registered difference decided under ). -use sdm_contract::{CoreError, Detail, Scalar, Sentence}; +use sdm_contract::{CoreError, Sentence}; use sdm_engine::labels::{self, Labels, Target}; use sdm_engine::sample::out_of_range; use sdm_engine::time::offset::Offset; -use sdm_request::payload::{LagColumn, LagValues, PAYLOAD_BYTES}; +use sdm_request::payload::{LagColumn, LagValues}; /// The field a lag's refusal names. const FIELD: &str = "lag_timesteps"; -/// The fewest bytes a lagged column adds to a payload: its declaration in -/// the instance table's schema (`"__kumo_arl0__": {"dtype": "bool"}`). -const COLUMN_BYTES: usize = 30; - -/// The fewest bytes one lagged cell adds: the shortest value (`0.0`, `true` -/// or `null`) and its separator. -const CELL_BYTES: usize = 4; - /// `offset` taken `times` times, as pandas multiplies a `DateOffset`: a /// count of its unit `times` as large; past what the count holds, refused /// as a time out of range naming `lag_timesteps`, as pandas overflows. @@ -143,33 +135,6 @@ pub(crate) struct Lag { } impl Lag { - /// Refuses lags that would make a payload of `rows` instance rows - /// larger than the endpoint takes, before any column is computed, as - /// the payload's limit refuses it. - pub fn fits(&self, rows: usize) -> Result<(), CoreError> { - let least = usize::try_from(self.steps) - .ok() - .and_then(|steps| { - rows.checked_mul(CELL_BYTES)? - .checked_add(COLUMN_BYTES)? - .checked_mul(steps) - }) - .unwrap_or(usize::MAX); - if least > PAYLOAD_BYTES { - return Err(CoreError::new( - Sentence::LagPastPayload, - "the request is larger than the endpoint takes", - ) - .with_field("field", Detail::text("payload")) - .with_field("lag_timesteps", Detail::Scalar(Scalar::UInt64(self.steps))) - .with_field( - "limit", - Detail::Scalar(Scalar::UInt64(PAYLOAD_BYTES as u64)), - )); - } - Ok(()) - } - /// The lagged columns of the examples at `kept` (positions among the /// examples the lags were read for: the whole request's, the gathered /// context before narrowing and every entity predicted for), @@ -239,6 +204,7 @@ impl Lag { #[cfg(test)] mod tests { use super::*; + use sdm_contract::Detail; use sdm_contract::ErrorCode; use sdm_contract::pql::TimeUnit; use sdm_engine::labels::{Aggregation, Constant, RelOp}; @@ -520,8 +486,7 @@ mod tests { } /// Steps that reach outside what nanoseconds hold, or past what a count - /// holds, are refused naming `lag_timesteps`; a payload they would make - /// larger than the endpoint takes, before anything is computed. + /// holds, are refused naming `lag_timesteps`. #[test] fn too_many_steps_are_refused_by_name() { for steps in [100_000, u64::MAX] { @@ -529,21 +494,5 @@ mod tests { assert_eq!(e.code, ErrorCode::ValueOutOfRange); assert_eq!(e.fields["field"], Detail::text(FIELD)); } - let lag = single( - 10_000_000, - Aggregation::Count, - Offset::of(0, TimeUnit::Seconds), - Offset::of(1, TimeUnit::Seconds), - None, - vec![0, 0], - Rows { - batches: vec![], - values: labels::Values::Ones(0), - times: vec![], - }, - ); - let e = lag.fits(2).err().unwrap(); - assert_eq!(e.code, ErrorCode::InvalidRequest); - assert_eq!(e.fields["field"], Detail::text("payload")); } } diff --git a/rust/crates/sdm-core/src/materialize.rs b/rust/crates/sdm-core/src/materialize.rs index 9d2799e71..bfea08144 100644 --- a/rust/crates/sdm-core/src/materialize.rs +++ b/rust/crates/sdm-core/src/materialize.rs @@ -49,8 +49,7 @@ //! narrowed to the size asked, the hops the options ask bounded, the //! entity count, the reserved names, the statistic, the inference //! options, a static target's columns kept out of what is read and sent, -//! the subgraph's 15 tables, the payload's layout and byte limit -//! ([`sdm_request::payload`]), and the notices of what the request leaves +//! the payload's layout ([`sdm_request::payload`]), and the notices of what the request leaves //! out, each a code and fields the host words; and it refuses with //! `UNSUPPORTED_REQUEST` naming the rule ([`sdm_engine::not_yet`]) every //! input whose request takes a rule it does not port yet (register entry @@ -139,18 +138,6 @@ const DEFAULT_SEED: u128 = 42; /// How many times as many candidates as examples a run tries /// (`max_pq_iterations`' default). const ITERATIONS: usize = 10; -/// The most tables a request's subgraph carries (`_MAX_SUBGRAPH_TABLES`). -const SUBGRAPH_TABLES: usize = 15; -/// The most entities one `materialize` gathers where the host names no -/// limit (`main`'s `MOST_ENTITIES`): every call's payload is built, with -/// its own context, before any is sent, so the whole population is held at -/// once. -pub const MOST_ENTITIES: u64 = 100_000; -/// The most model calls one request is gathered as where the host names no -/// limit (`main`'s `MOST_CALLS`): a context is gathered for every call. -pub const MOST_CALLS: u32 = 100; -/// The most rows an instance table may hold (`MAX_TABLE_ROWS`). -const TABLE_ROWS: usize = 10_000; /// How many examples the reference labels at once, stopping once it has /// the run mode's (`_sample_target_set`'s `batch_size`): the first batch /// holds every example a context takes whenever all of it is labelled. @@ -183,12 +170,6 @@ pub(crate) struct Inputs { pub options: Vec, /// The most steps a forecast is asked as (`Materialize.most_parts`). pub most_parts: Option, - /// The most entities one `materialize` gathers - /// (`Materialize.most_entities`). - pub most_entities: Option, - /// The most calls one request is gathered as - /// (`Materialize.most_calls`). - pub most_calls: Option, pub facts: HostFacts, /// The zones the run resolves names with: the host's local zone, which /// places a date literal's two-digit year (`pql::local_year`). @@ -2904,7 +2885,6 @@ pub(crate) async fn run(asker: Asker, inputs: Inputs) -> Result, -) -> Result<(), CoreError> { - let most = most.unwrap_or(MOST_ENTITIES); - let total = entities.saturating_mul(times); - if total <= most { - return Ok(()); - } - Err(CoreError::new( - if times == 1 { - Sentence::MostEntities - } else { - Sentence::MostEntitiesParts - }, - "more entities were asked for than one materialize holds at once", - ) - .with_field("field", Detail::text("indices")) - .with_field("entities", Detail::Scalar(Scalar::UInt64(entities))) - .with_field("gathered_times", Detail::Scalar(Scalar::UInt64(times))) - .with_field("total", Detail::Scalar(Scalar::UInt64(total))) - .with_field("limit", Detail::Scalar(Scalar::UInt64(most)))) -} - /// A request's payload and query, attached. pub(crate) fn attach_request( asker: &Asker, @@ -3137,8 +3087,6 @@ pub(crate) async fn one(asker: &Asker, inputs: Inputs) -> Result Result Result mode.context_examples(), + options::RunMode::Best => mode.context_examples().max(asked_examples.unwrap_or(0)), + }; // `max_pq_iterations` times as many candidates as examples; a // float's count is no slice bound for a temporal query's walk, the // engine's `TypeError`, the caller's error. @@ -3872,19 +3819,6 @@ pub(crate) async fn one(asker: &Asker, inputs: Inputs) -> Result most as usize { - return Err(CoreError::new( - Sentence::MostCalls, - "the entities asked for are gathered as more calls than one materialize holds at once", - ) - .with_field("field", Detail::text("indices")) - .with_field("entities", count(num_test)) - .with_field("calls", count(calls)) - .with_field("rows_per_call", count(per_call)) - .with_field("limit", Detail::Scalar(Scalar::UInt32(most)))); - } // How many candidates the call asked be kept (`_candidates_to_rank`, // ), which the engine writes into the task; then the inference // options, read for the task's config class, as the engine reads them @@ -3947,16 +3881,6 @@ pub(crate) async fn one(asker: &Asker, inputs: Inputs) -> Result TABLE_ROWS { - return Err(invalid( - Sentence::ContextPastRows, - "the context holds more rows than a request takes", - "query", - )); - } - // The rows the largest call scores (`_the_largest_batch`), which a - // payload past the endpoint's body names as the size to come down from. - let largest = per_call.min(num_test); let train_anchors = anchors.len(); let entity_names = crate::subgraph::sample_columns(&graph, entity, &excluded); // The labelled context's examples before narrowing, then the entities @@ -3976,7 +3900,7 @@ pub(crate) async fn one(asker: &Asker, inputs: Inputs) -> Result Result SUBGRAPH_TABLES { - return Err(invalid( - Sentence::SubgraphPastTables, - "the request's subgraph carries more tables than the endpoint reads", - "tables", - ) - .with_field("tables", count(walked.tables.len())) - .with_field("limit", count(SUBGRAPH_TABLES))); - } sent.extend(walked.tables.iter().map(|t| t.name.clone())); // The lagged columns of this call's examples: the narrowed // context's, then this call's own entities, each its own row's, // sliced from the whole request's columns, so each column's type // is the request's whatever this call's rows hold, typed // over the gathered context before narrowing; the - // columns are computed at the first call's payload, where the - // reference's size refusal falls, held to the largest call's rows. + // columns are computed at the first call's payload. if lag_columns.is_none() && let Some(lag) = &lag { - lag.fits(num_train + largest)?; lag_columns = Some( lag.columns( &(0..num_train) @@ -4213,7 +4123,6 @@ pub(crate) async fn one(asker: &Asker, inputs: Inputs) -> Result TABLE_ROWS { - return Err(refuse("context exceeds the model row limit")); - } - refuse_entities(predict.num_rows() as u64, 1, None)?; let seed = call .random_seed .to_u128() @@ -425,9 +421,6 @@ async fn run( Some(seed), ) .await?; - if walked.tables.len() > SUBGRAPH_TABLES { - return Err(refuse("sampled graph exceeds the model table limit")); - } if let Some(destination) = destination && !walked.tables.iter().any(|t| t.name == destination.name) { @@ -452,7 +445,6 @@ async fn run( options: options.clone(), statistic: None, top_k: None, - rows_per_call: per_call, lags: vec![], float_text: crate::pql::float_text, }; diff --git a/rust/crates/sdm-core/src/materialize/frames.rs b/rust/crates/sdm-core/src/materialize/frames.rs index cf826199c..46da643d4 100644 --- a/rust/crates/sdm-core/src/materialize/frames.rs +++ b/rust/crates/sdm-core/src/materialize/frames.rs @@ -133,7 +133,7 @@ impl FrameGraph { &self, graph: &Graph, seeds: SeedRows<'_>, - hops: &[options::Hop], + hops: &options::Hops, excluded: &[(String, String)], seed: Option, ) -> Result { @@ -144,7 +144,10 @@ impl FrameGraph { } = seeds; let rows = self.0.snapshot.entity_rows(&entity.name, keys)?; let mut counts = Vec::new(); - for hop in hops { + // Hops past as many as the snapshot holds rows reach nothing more, + // so a count of hops past it is walked as that many. + let most = self.0.snapshot.rows().saturating_add(1); + for hop in (0..most).map_while(|at| hops.get(at)) { match hop { options::Hop::Keep(n) => { counts.push(i64::try_from(*n).map_err(|_| not_yet("frame_neighbor_count"))?) @@ -365,8 +368,6 @@ pub(crate) async fn materialize( values, options: call.options, most_parts: call.most_parts, - most_entities: call.most_entities, - most_calls: call.most_calls, facts, zones, memo: None, diff --git a/rust/crates/sdm-core/src/predict.rs b/rust/crates/sdm-core/src/predict.rs index 906e3cc0e..6229eb3eb 100644 --- a/rust/crates/sdm-core/src/predict.rs +++ b/rust/crates/sdm-core/src/predict.rs @@ -36,9 +36,9 @@ use sdm_contract::ops::{ModelEndpoint, OperationResult, Predicted}; use sdm_contract::run::Endpoint; use sdm_contract::{CoreError, CoreWarning, Detail, Scalar, Sentence}; use sdm_request::predict::{ - Notice, Part, absent, absent_notice, bad_response, body, by_step, call_bytes, call_starts, - empty, layout, left_out, merge, nothing_to_score, numbered_from, predict_rows, preflight, - prepare, refused, steps_unexplained, table, + Notice, Part, absent, absent_notice, bad_response, body, by_step, call_starts, empty, layout, + left_out, merge, nothing_to_score, numbered_from, predict_rows, preflight, prepare, refused, + steps_unexplained, table, }; use sdm_request::serving::{self, Failure}; use sdm_wire::json::{self, Value}; @@ -445,12 +445,12 @@ pub(crate) async fn one( &bodies, inputs.supports_sessions && inputs.endpoint.is_none(), ); - // Validate all full calls before any network effect, including their size. + // Validate all full calls before any network effect. // Retain only the small scoring half alongside encoded fallback bytes. let plans = bodies .into_iter() .map(|body| { - let bytes = call_bytes(&body)?; + let bytes = body.to_bytes(); let scoring = if session.is_some() { sdm_request::frame_session::subset( &body, diff --git a/rust/crates/sdm-core/src/ranking.rs b/rust/crates/sdm-core/src/ranking.rs index 97d311259..2919078d4 100644 --- a/rust/crates/sdm-core/src/ranking.rs +++ b/rust/crates/sdm-core/src/ranking.rs @@ -34,7 +34,7 @@ use sdm_wire::json::Value; use crate::materialize::{ Call, Gathered, Inputs, MOST_PARTS, REQUEST_STATE_VERSION, asked_rows_per_call, attach_request, - one, refuse_entities, + one, }; use crate::pql::RankingPlan; use crate::run::Asker; @@ -168,14 +168,11 @@ pub(crate) async fn materialize( .map(|digits| digits.parse::().unwrap_or(u32::MAX)), }; // `_in_parts`, before anything is gathered, as the client refuses them - // (`main`'s 1fc5a686): the batch size asked for; a question over more - // entities than one call scores, since a part is one call and a + // (`main`'s 1fc5a686): the batch size asked for; and a question over + // more entities than one call scores, since a part is one call and a // candidate is reported unscored for the whole ranking, so one cold // batch would drop it from every row - // (`refuse_a_part_that_would_take_several_calls`); and the population - // each question gathers whole, held as many times over as there are - // questions (`refuse_more_entities_than_fit_in_memory`), past the - // host's limit, 100,000 where it names none. + // (`refuse_a_part_that_would_take_several_calls`). let per_call = sdm_request::options::rows_one_call_scores(asked_rows_per_call(inputs.values.as_ref())?); let entities = inputs.indices.as_ref().map_or(0, |data| { @@ -195,7 +192,6 @@ pub(crate) async fn materialize( .with_field("parts", Detail::Scalar(Scalar::UInt64(parts))) .with_field("rows_per_call", Detail::Scalar(Scalar::UInt64(per_call)))); } - refuse_entities(entities, parts, inputs.most_entities)?; // Each question gathered with the call's values but `top_k`, which is // the whole ranking's, each by a materializer of its own, so with no // memo of another's reads; the materializer's own memo is left as it diff --git a/rust/crates/sdm-core/src/subgraph.rs b/rust/crates/sdm-core/src/subgraph.rs index 4d9751860..6199311ae 100644 --- a/rust/crates/sdm-core/src/subgraph.rs +++ b/rust/crates/sdm-core/src/subgraph.rs @@ -48,7 +48,7 @@ use sdm_contract::{CoreError, CoreWarning, Detail, Scalar, Sentence}; use sdm_engine::graph::{Graph, Table}; use sdm_engine::keys::{self, Key}; use sdm_engine::sample::{self, SEED_TIME}; -use sdm_request::options::Hop; +use sdm_request::options::{Hop, Hops}; use sdm_request::payload::{SampledColumn, SampledLink, SampledTable}; use crate::describe::{ask, ask_all_vec}; @@ -64,24 +64,38 @@ struct Visit { /// Each row's number, by its key and example (the reference's /// `Mapper`), for a table with a key. nodes: BTreeMap<(Key, usize), usize>, - /// The rows reached at each hop, the entity's first. + /// The rows reached at each hop, the entity's first; a hop past the + /// end reached none. counts: Vec, /// The frames visited so far. offset: usize, } impl Visit { - fn new(name: &str, hops: usize) -> Visit { + fn new(name: &str) -> Visit { Visit { name: name.to_owned(), frames: Vec::new(), batches: Vec::new(), nodes: BTreeMap::new(), - counts: vec![0; hops + 1], + counts: Vec::new(), offset: 0, } } + /// The rows reached at hop `hop`. + fn reached(&self, hop: usize) -> usize { + self.counts.get(hop).copied().unwrap_or(0) + } + + /// Counts `rows` more reached at hop `hop`. + fn add_reached(&mut self, hop: usize, rows: usize) { + if self.counts.len() <= hop { + self.counts.resize(hop + 1, 0); + } + self.counts[hop] += rows; + } + fn rows(&self) -> usize { self.counts.iter().sum() } @@ -119,10 +133,11 @@ pub(crate) struct Walk<'a> { /// The hops walked, each with the neighbors it keeps of each row: the /// run mode's two by default, or as the sampling options ask /// (`num_hops`, `num_neighbors`, [`options::neighbors`]); the walk ends - /// at a hop of size zero. + /// at a hop of size zero, after the last, or at a hop no row is walked + /// from, past which nothing is reached. /// /// [`options::neighbors`]: sdm_request::options::neighbors - pub neighbors: &'a [Hop], + pub neighbors: &'a Hops, /// The features left out, by table: a static target's columns, which /// the reference's sampler neither reads nor sends /// (`get_exclude_cols_dict`, `exclude_cols_dict`). @@ -293,7 +308,7 @@ impl Walk<'_> { /// [`sample_columns`]. pub(crate) async fn run(&self, entity_rows: RecordBatch) -> Result { let examples = entity_rows.num_rows(); - let mut visits = vec![Visit::new(&self.entity.name, self.neighbors.len())]; + let mut visits = vec![Visit::new(&self.entity.name)]; let mut edges: Vec = Vec::new(); { let entity = &mut visits[0]; @@ -311,9 +326,17 @@ impl Walk<'_> { } entity.frames.push(entity_rows); entity.batches.push((0..examples).collect()); - entity.counts[0] = examples; + entity.add_reached(0, examples); } - for (hop, neighbors) in self.neighbors.iter().enumerate() { + for hop in 0.. { + let Some(neighbors) = self.neighbors.get(hop) else { + break; + }; + // A hop no table has rows to walk from reaches none, nor does + // any after it: the walk ends, as it would hop by hop. + if visits.iter().all(|visit| visit.reached(hop) == 0) { + break; + } // A hop of size zero ends the walk (`neighbors == 0`). let neighbors = match neighbors { Hop::Stop => break, @@ -352,7 +375,7 @@ impl Walk<'_> { neighbors: &sdm_contract::data::NeighborLimit, ) -> Result<(), CoreError> { let at = position(visits, name)?; - if visits[at].counts[hop] == 0 { + if visits[at].reached(hop) == 0 { return Ok(()); } let table = table_named(self.graph, name)?; @@ -479,7 +502,7 @@ impl Walk<'_> { return Err(internal("a row looked up was already reached")); } } - dst_visit.counts[hop + 1] += examples.len(); + dst_visit.add_reached(hop + 1, examples.len()); dst_visit.frames.push(added); dst_visit.batches.push(examples); for &i in &missing { @@ -641,7 +664,7 @@ impl Walk<'_> { ), }; let kept_examples: Vec = kept.iter().map(|&i| examples[i]).collect(); - src_visit.counts[hop + 1] += kept.len(); + src_visit.add_reached(hop + 1, kept.len()); src_visit.frames.push(take(&fetched, &kept)?); src_visit.batches.push(kept_examples); edge(edges, src, fkey, name, false).extend(rows, cols); @@ -840,8 +863,7 @@ fn reach(visits: &mut Vec, name: &str) -> usize { match visits.iter().position(|v| v.name == name) { Some(at) => at, None => { - let hops = visits[0].counts.len() - 1; - visits.push(Visit::new(name, hops)); + visits.push(Visit::new(name)); visits.len() - 1 } } diff --git a/rust/crates/sdm-core/src/tabular_arrow.rs b/rust/crates/sdm-core/src/tabular_arrow.rs index 4ff4d8346..a89983268 100644 --- a/rust/crates/sdm-core/src/tabular_arrow.rs +++ b/rust/crates/sdm-core/src/tabular_arrow.rs @@ -873,7 +873,7 @@ fn materialize( let decision = sdm_engine::tabular::context_decision( candidates.len(), input.num_context_samples, - sdm_request::predict::CONTEXT_ROWS_MAX, + sdm_request::predict::CONTEXT_ROWS_DEFAULT, ) .map_err(|_| invalid("context sample count is invalid"))?; let context_rows = if decision.reduced { diff --git a/rust/crates/sdm-core/src/tabular_selection.rs b/rust/crates/sdm-core/src/tabular_selection.rs index c11020253..8496d8d90 100644 --- a/rust/crates/sdm-core/src/tabular_selection.rs +++ b/rust/crates/sdm-core/src/tabular_selection.rs @@ -30,7 +30,6 @@ pub(crate) fn filter(input: FilterTabularRows) -> Result TabularCountError { match error { tabular::CountError::Zero => TabularCountError::Zero, - tabular::CountError::AboveLimit => TabularCountError::AboveLimit, tabular::CountError::AbovePopulation => TabularCountError::AbovePopulation, } } @@ -39,7 +38,7 @@ pub(crate) fn decide(input: DecideTabularContext) -> TabularContextDecision { match tabular::context_decision( input.population, input.requested, - sdm_request::predict::CONTEXT_ROWS_MAX, + sdm_request::predict::CONTEXT_ROWS_DEFAULT, ) { Ok(value) => TabularContextDecision::Selected { wanted: value.wanted, diff --git a/rust/crates/sdm-core/tests/attachments.rs b/rust/crates/sdm-core/tests/attachments.rs index 64d0d3bf0..57dd02b97 100644 --- a/rust/crates/sdm-core/tests/attachments.rs +++ b/rust/crates/sdm-core/tests/attachments.rs @@ -49,7 +49,6 @@ const READ: &[&str] = &[ "DecideTabularTask.input", "OrderSampledTabularRows.input", "SelectTabularRows.input", - "CheckTabularCap.input", "CheckDirectShape.input", "BindDirect.input", "CheckDirectRows.input", diff --git a/rust/crates/sdm-core/tests/dispatch.rs b/rust/crates/sdm-core/tests/dispatch.rs index 63acae7a6..067893ab9 100644 --- a/rust/crates/sdm-core/tests/dispatch.rs +++ b/rust/crates/sdm-core/tests/dispatch.rs @@ -672,8 +672,6 @@ fn materialize(seed: Option) -> Operation { values: None, options: vec![], most_parts: None, - most_entities: None, - most_calls: None, candidates: None, sampler_state: None, }) diff --git a/rust/crates/sdm-core/tests/held_schema.rs b/rust/crates/sdm-core/tests/held_schema.rs index 21be4e556..0d46997a9 100644 --- a/rust/crates/sdm-core/tests/held_schema.rs +++ b/rust/crates/sdm-core/tests/held_schema.rs @@ -241,8 +241,6 @@ fn materialize(held: &HeldSchema) -> Run { values: None, options: vec![], most_parts: None, - most_entities: None, - most_calls: None, candidates: None, sampler_state: None, }); diff --git a/rust/crates/sdm-core/tests/materialize.rs b/rust/crates/sdm-core/tests/materialize.rs index 96b73ffec..064695c3f 100644 --- a/rust/crates/sdm-core/tests/materialize.rs +++ b/rust/crates/sdm-core/tests/materialize.rs @@ -229,8 +229,6 @@ fn materialize_start( values: None, options: vec![], most_parts: None, - most_entities: None, - most_calls: None, candidates: None, sampler_state: None, }); @@ -1161,11 +1159,6 @@ fn the_options_the_host_passes_through_are_refused_by_name() { for (asked, code) in [ ("0", ErrorCode::InvalidRequest), ("-3", ErrorCode::InvalidRequest), - ("10001", ErrorCode::UnsupportedRequest), - ( - "1267650600228229401496703205376", - ErrorCode::UnsupportedRequest, - ), ("2.5", ErrorCode::InvalidRequest), ] { let err = valued( @@ -1187,13 +1180,25 @@ fn the_options_the_host_passes_through_are_refused_by_name() { assert_eq!(err.code, ErrorCode::InvalidRequest, "{values}"); assert_eq!(err.fields["field"], Detail::text(field), "{values}"); } - let past = valued(r#"{"num_hops": 7}"#, &[]).unwrap_err(); - assert_eq!(past.code, ErrorCode::UnsupportedRequest); - assert_eq!(past.fields["field"], Detail::text("num_hops")); - assert!(!past.fields.contains_key("rule"), "the bound, not the rule"); - // The sampling options taken reach the first read. + // Reject unsupported depth before any provider read. + for (values, field) in [ + (r#"{"num_hops": 7}"#, "num_hops"), + (r#"{"num_hops": 1000000}"#, "num_hops"), + ( + r#"{"num_neighbors": [8, 8, 4, 4, 2, 2, 1]}"#, + "num_neighbors", + ), + ] { + let err = valued(values, &[]).unwrap_err(); + assert_eq!(err.code, ErrorCode::UnsupportedRequest); + assert_eq!(err.fields["field"], Detail::text(field)); + assert_eq!(err.fields["limit"], Detail::Scalar(Scalar::UInt64(6))); + } + // Supported sampling options reach the first read. for values in [ r#"{"num_hops": 3}"#, + r#"{"num_hops": 6}"#, + r#"{"num_neighbors": [8, 8, 4, 4, 2, 2]}"#, r#"{"num_neighbors": [4, 0]}"#, r#"{"random_seed": null}"#, r#"{"max_pq_iterations": 2, "use_prediction_time": true}"#, diff --git a/rust/crates/sdm-core/tests/predict.rs b/rust/crates/sdm-core/tests/predict.rs index c9f517a61..593d726f7 100644 --- a/rust/crates/sdm-core/tests/predict.rs +++ b/rust/crates/sdm-core/tests/predict.rs @@ -1266,42 +1266,3 @@ fn an_output_named_and_left_out_is_noted() { Detail::List(vec![Scalar::Utf8("quantiles".into())]) ); } - -/// The call's size: the core writes the call's bytes, which the host sends -/// unchanged, and refuses a call past the endpoint's limit before the model -/// is called (register PD-2, fix round 1); counted to the byte, -/// with characters past ASCII counted as the bytes written. -#[test] -fn a_call_past_the_limit_is_refused_before_it_is_sent() { - // Pad a non-truncated metadata field; diagnostic query clipping is independent. - let padded = |padding: &str| { - payload_text().replace( - "\"metadata\":{", - &format!("\"metadata\":{{\"caller_note\":\"{padding}\","), - ) - }; - let called = |payload: String| -> Result { - let mut run = predict_run(REQUEST_STATE_VERSION, payload, "kumo-relational").unwrap(); - match run.next()? { - Step::CallModel(call) => match run.take_attachment(call.body) { - Some(Attachment::Bytes(body)) => Ok(body.len()), - _ => panic!("the body is attached"), - }, - other => panic!("not a call: {other:?}"), - } - }; - let limit = sdm_request::payload::PAYLOAD_BYTES; - let base = called(padded("")).unwrap(); - // ASCII to the limit, exactly: taken; one byte more: refused. - assert_eq!(called(padded(&"a".repeat(limit - base))).unwrap(), limit); - let past = called(padded(&"a".repeat(limit - base + 1))).unwrap_err(); - assert_eq!(past.code, ErrorCode::InvalidRequest); - assert_eq!(past.fields["field"], text("call")); - // Three-byte characters, each counted as its three bytes written. - let euros = (limit - base) / 3; - let rest = limit - base - 3 * euros; - let at = format!("{}{}", "\u{20ac}".repeat(euros), "a".repeat(rest)); - assert_eq!(called(padded(&at)).unwrap(), limit); - let over = format!("{}{}", "\u{20ac}".repeat(euros + 1), "a".repeat(rest)); - assert!(called(padded(&over)).is_err()); -} diff --git a/rust/crates/sdm-core/tests/view_captures.rs b/rust/crates/sdm-core/tests/view_captures.rs index f63df3ab0..033c3473c 100644 --- a/rust/crates/sdm-core/tests/view_captures.rs +++ b/rust/crates/sdm-core/tests/view_captures.rs @@ -1082,8 +1082,6 @@ fn materialize_query( values: None, options: vec![], most_parts: None, - most_entities: None, - most_calls: None, candidates: None, sampler_state: None, }), diff --git a/rust/crates/sdm-engine/src/frames.rs b/rust/crates/sdm-engine/src/frames.rs index 1c392bd1b..f0b4dd395 100644 --- a/rust/crates/sdm-engine/src/frames.rs +++ b/rust/crates/sdm-engine/src/frames.rs @@ -237,6 +237,13 @@ pub enum FrameNeighbor { } impl Snapshot { + /// How many rows the snapshot admits across its tables: a walk reaches + /// no row it has not reached at any hop past this many, since each hop + /// that reaches anything reaches at least one row anew. + pub fn rows(&self) -> usize { + self.tables.values().map(|table| table.valid.len()).sum() + } + /// Physical storage of one admitted column, without scanning or sampling rows. pub fn column_type(&self, table: &str, column: &str) -> Result { let rows = &self diff --git a/rust/crates/sdm-engine/src/tabular.rs b/rust/crates/sdm-engine/src/tabular.rs index b84a3c340..a3cbf6e39 100644 --- a/rust/crates/sdm-engine/src/tabular.rs +++ b/rust/crates/sdm-engine/src/tabular.rs @@ -78,23 +78,19 @@ pub struct ContextDecision { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum CountError { Zero, - AboveLimit, AbovePopulation, } -/// The composition supplies the model limit; this engine owns no capability. +/// The composition supplies the default sample size; this engine owns no capability. pub fn context_decision( population: usize, requested: Option, - limit: usize, + default: usize, ) -> Result { - let wanted = requested.unwrap_or(limit); + let wanted = requested.unwrap_or(default); if wanted == 0 { return Err(CountError::Zero); } - if wanted > limit { - return Err(CountError::AboveLimit); - } let reduced = population > wanted; Ok(ContextDecision { wanted, @@ -135,10 +131,7 @@ mod tests { .unwrap() .advise_default_reduction ); - assert_eq!( - context_decision(0, Some(11), 10), - Err(CountError::AboveLimit) - ); + assert!(context_decision(20, Some(11), 10).unwrap().reduced); assert_eq!( sample_offsets(2, decision.wanted), Err(CountError::AbovePopulation) diff --git a/rust/crates/sdm-host/tests/runs.rs b/rust/crates/sdm-host/tests/runs.rs index 94393bf4e..01ea45f51 100644 --- a/rust/crates/sdm-host/tests/runs.rs +++ b/rust/crates/sdm-host/tests/runs.rs @@ -720,8 +720,6 @@ fn request_state_leaves_one_run_as_bytes_and_returns_under_the_host_s_id() { values: None, options: vec![], most_parts: None, - most_entities: None, - most_calls: None, candidates: None, sampler_state: None, }), diff --git a/rust/crates/sdm-request/src/options.rs b/rust/crates/sdm-request/src/options.rs index ffa61d7e8..ea481b2c2 100644 --- a/rust/crates/sdm-request/src/options.rs +++ b/rust/crates/sdm-request/src/options.rs @@ -591,14 +591,44 @@ pub enum Hop { Stop, } +/// The hops a walk takes, each with the neighbors it keeps of each row: the +/// sizes listed, then the last of them again for as many hops more as were +/// asked. A walk reads them one hop at a time ([`Hops::get`]), so a count +/// of hops far past what the data holds costs nothing: the walk ends at +/// the first hop that reaches no row. +#[derive(Debug, Clone, PartialEq)] +pub struct Hops { + listed: Vec, + /// How many hops follow the listed ones, each the last listed size. + more: usize, +} + +impl Hops { + /// The size of hop `hop`, counted from zero; none past the last. + pub fn get(&self, hop: usize) -> Option<&Hop> { + match self.listed.get(hop) { + Some(size) => Some(size), + None if hop - self.listed.len() < self.more => self.listed.last(), + None => None, + } + } +} + +impl From> for Hops { + fn from(listed: Vec) -> Self { + Hops { listed, more: 0 } + } +} + /// The hops the walk takes, each with its size, as the engine resolves /// them (`_resolve_options`): `num_neighbors` where it is given, each size /// read as [`hop`] reads it; else the first `num_hops` of the run mode's sizes -/// (`_DEFAULT_NUM_NEIGHBORS`), two where it is not named, and a `num_hops` +/// (`_DEFAULT_NUM_NEIGHBORS`), two where it is not named, each hop past the +/// sizes the mode lists keeping as many as its last; and a `num_hops` /// named as none, which the engine cannot compare with its bounds, /// `INVALID_REQUEST` (`not_a_whole_number`), as the engine's `TypeError` -/// is the caller's. Call it after [`hops`] has bounded the count. -pub fn neighbors(asked: &Asked, mode: RunMode) -> Result, CoreError> { +/// is the caller's. Call it after [`hops`] has checked the count. +pub fn neighbors(asked: &Asked, mode: RunMode) -> Result { let Some(given) = &asked.neighbors else { if asked.num_hops_none { return Err(mistyped( @@ -609,14 +639,13 @@ pub fn neighbors(asked: &Asked, mode: RunMode) -> Result, CoreError> { } let hops = asked .num_hops - .and_then(|n| n.magnitude) - .map_or(2, |n| usize::try_from(n).unwrap_or(usize::MAX)); - return Ok(mode - .all_neighbors() - .into_iter() - .take(hops) - .map(Hop::Keep) - .collect()); + .map_or(Some(2), |n| n.magnitude) + .map_or(usize::MAX, |n| usize::try_from(n).unwrap_or(usize::MAX)); + let sizes = mode.all_neighbors(); + return Ok(Hops { + listed: sizes.into_iter().take(hops).map(Hop::Keep).collect(), + more: hops.saturating_sub(sizes.len()), + }); }; given .iter() @@ -624,7 +653,8 @@ pub fn neighbors(asked: &Asked, mode: RunMode) -> Result, CoreError> { .map(|(at, size)| { hop(size).map_err(|e| e.with_field("hop", Detail::Scalar(Scalar::UInt64(at as u64)))) }) - .collect() + .collect::, _>>() + .map(Hops::from) } /// One hop's size, as the reference's DuckDB sampler reads the value it @@ -790,14 +820,13 @@ pub fn rows_per_call(given: &Value) -> Result, CoreError> { } } -/// The most rows one model call scores (`predict_rows_max`, the serving -/// layer's `TFM_MAX_TEST_ROWS`, which the reference's client and engine -/// hold at 10,000 from `main`'s 1fc5a686). +/// How many rows one model call scores where the caller names no size +/// (`predict_rows_max`, the serving layer's `TFM_MAX_TEST_ROWS` default): +/// a batching default, not a cap. pub const PREDICT_ROWS: u64 = 10_000; -/// How many entities one call scores, as the caller asked or as the -/// endpoint allows (`rows_one_call_scores`): the caller's size only ever -/// lowers the endpoint's. +/// How many entities one call scores, as the caller asked, else the +/// default (`rows_one_call_scores`). pub fn rows_one_call_scores(asked: Option) -> u64 { rows_one_task_call_scores(asked, BatchTask::Ordinary) } @@ -810,14 +839,13 @@ pub enum BatchTask { TemporalLink, } -/// Apply the task's serving limit after validating the requested positive size. -/// PQL and supplied examples use the same policy; hosts do not split rows. +/// The rows one call scores: the requested positive size, else the task's +/// default batch. PQL and supplied examples use the same policy. pub fn rows_one_task_call_scores(asked: Option, task: BatchTask) -> u64 { - let limit = match task { + asked.unwrap_or(match task { BatchTask::Ordinary => PREDICT_ROWS, BatchTask::TemporalLink => 200, - }; - asked.map_or(limit, |n| n.min(limit)) + }) } /// A task's kind, as the engine names it. @@ -860,7 +888,8 @@ impl RunMode { } } - /// The most context examples the mode gathers. + /// The most context examples the mode gathers where the caller asks + /// for no more: a best run gathers as many as are asked past it. pub fn context_examples(self) -> usize { match self { RunMode::Fast => 1_000, @@ -881,9 +910,8 @@ impl RunMode { /// The run mode a context size asks for, as the client chooses it /// (`_run_mode_for`, with `num_context_samples`' bound of /// `_validate_materialize_args`): none or up to a fast run's examples, a -/// fast run; up to a best run's, a best one. Below 1 is `INVALID_REQUEST`; -/// past a best run's examples, `UNSUPPORTED_REQUEST`, as the endpoint takes -/// no more. +/// fast run; past it, a best one, gathering as many as are asked. Below 1 +/// is `INVALID_REQUEST`. pub fn run_mode(asked: Option, given: Option<&str>) -> Result { // A refusal names the size as the caller gave it, its JSON text. let named = |refused: CoreError| match given { @@ -908,29 +936,15 @@ pub fn run_mode(asked: Option, given: Option<&str>) -> Result Ok(RunMode::Fast), - Some(n) if n <= RunMode::Best.context_examples() as u128 => Ok(RunMode::Best), - _ => Err(named( - CoreError::new( - Sentence::NumContextSamplesPastMost, - "num_context_samples is past the most context the endpoint takes", - ) - .with_field("field", Detail::text("num_context_samples")) - .with_field( - "limit", - Detail::Scalar(Scalar::UInt64(RunMode::Best.context_examples() as u64)), - ), - )), + _ => Ok(RunMode::Best), } } -/// The most hops the endpoint reads (`hops_max`). -pub const HOPS_MAX: u128 = 6; - -/// The hops the sampling options ask for, as the client bounds them +/// The hops the sampling options ask for, as the client checks them /// (`_check_shape`): `num_neighbors`' length where it is given, else /// `num_hops`; none, or fewer than one, is `INVALID_REQUEST` (a request -/// that crosses no relationship), more than [`HOPS_MAX`] -/// `UNSUPPORTED_REQUEST`. +/// that crosses no relationship). Sampling supports at most six hops. +/// An explicit neighbor list determines depth when supplied. pub fn hops(num_hops: Option, num_neighbors: Option) -> Result<(), CoreError> { let ( field, @@ -943,34 +957,27 @@ pub fn hops(num_hops: Option, num_neighbors: Option) -> Result (None, Some(n)) => ("num_hops", n), (None, None) => return Ok(()), }; - // How many hops were asked, as the host's words name them. - let asked = value.map(|n| format!("{}{n}", if negative && n > 0 { "-" } else { "" })); - let named = |error: CoreError| match &asked { - Some(n) => error.with_field("hops", Detail::text(n)), - None => error, - }; if negative || value == Some(0) { + // How many hops were asked, as the host's words name them. + let asked = value.map(|n| format!("{}{n}", if negative && n > 0 { "-" } else { "" })); let sentence = if field == "num_hops" { Sentence::NoHopNumHops } else { Sentence::NoHopNumNeighbors }; - return Err(named(invalid(sentence, field, "no_hop")) - .with_field("limit", Detail::Scalar(Scalar::UInt64(HOPS_MAX as u64)))); - } - if value.is_none_or(|n| n > HOPS_MAX) { - return Err(named( - CoreError::new( - if asked.is_some() { - Sentence::HopsPastEndpoint - } else { - Sentence::HopsPastEndpointUncounted - }, - "the sampling options ask more hops than the endpoint reads", - ) - .with_field("field", Detail::text(field)) - .with_field("limit", Detail::Scalar(Scalar::UInt64(HOPS_MAX as u64))), - )); + let refused = invalid(sentence, field, "no_hop"); + return Err(match asked { + Some(n) => refused.with_field("hops", Detail::text(n)), + None => refused, + }); + } + if value.is_none_or(|n| n > 6) { + return Err(CoreError::new( + Sentence::SamplingHopsLimit, + "sampling supports at most six hops", + ) + .with_field("field", Detail::text(field)) + .with_field("limit", Detail::Scalar(Scalar::UInt64(6)))); } Ok(()) } @@ -1370,26 +1377,23 @@ mod tests { #[test] fn the_run_mode_is_the_client_s() { assert_eq!(run_mode(None, None).unwrap(), RunMode::Fast); - assert_eq!(run_mode(int(false, Some(1)), None).unwrap(), RunMode::Fast); assert_eq!( run_mode(int(false, Some(1_000)), None).unwrap(), RunMode::Fast ); - assert_eq!( - run_mode(int(false, Some(1_001)), None).unwrap(), - RunMode::Best - ); - assert_eq!( - run_mode(int(false, Some(10_000)), None).unwrap(), - RunMode::Best - ); - for (asked, code) in [ - (int(false, Some(0)), ErrorCode::InvalidRequest), - (int(true, Some(5)), ErrorCode::InvalidRequest), - (int(false, Some(10_001)), ErrorCode::UnsupportedRequest), - (int(false, None), ErrorCode::UnsupportedRequest), + // Past a fast run's examples, a best run, however many are asked. + for asked in [ + int(false, Some(1_001)), + int(false, Some(200_000)), + int(false, None), ] { - assert_eq!(run_mode(asked, None).unwrap_err().code, code, "{asked:?}"); + assert_eq!(run_mode(asked, None).unwrap(), RunMode::Best); + } + for asked in [int(false, Some(0)), int(true, Some(5))] { + assert_eq!( + run_mode(asked, None).unwrap_err().code, + ErrorCode::InvalidRequest + ); } } @@ -1398,6 +1402,19 @@ mod tests { let some = |n: u128| int(false, Some(n)); assert!(hops(None, None).is_ok()); assert!(hops(some(6), None).is_ok()); + assert!(hops(None, some(6)).is_ok()); + for (count, neighbors) in [ + (some(7), None), + (some(1_000), None), + (None, some(7)), + (None, some(12)), + (int(false, None), None), + ] { + let error = hops(count, neighbors).unwrap_err(); + assert_eq!(error.code, ErrorCode::UnsupportedRequest); + assert_eq!(error.sentence, Sentence::SamplingHopsLimit); + assert_eq!(error.fields["limit"], Detail::Scalar(Scalar::UInt64(6))); + } assert!( hops(some(9), some(2)).is_ok(), "the neighbors' length counts" @@ -1414,14 +1431,6 @@ mod tests { hops(int(true, Some(1)), None).unwrap_err().code, ErrorCode::InvalidRequest ); - assert_eq!( - hops(some(7), None).unwrap_err().code, - ErrorCode::UnsupportedRequest - ); - assert_eq!( - hops(int(false, None), None).unwrap_err().code, - ErrorCode::UnsupportedRequest - ); } #[test] @@ -1942,15 +1951,32 @@ mod tests { #[test] fn the_hops_are_the_run_mode_s_first_num_hops_two_by_default() { let fast = |text: &str| neighbors(&asked(text), RunMode::Fast).unwrap(); - assert_eq!(fast("{}"), vec![Hop::Keep(32), Hop::Keep(32)]); + assert_eq!(fast("{}"), Hops::from(vec![Hop::Keep(32), Hop::Keep(32)])); assert_eq!( fast(r#"{"num_hops": 4}"#), - vec![Hop::Keep(32), Hop::Keep(32), Hop::Keep(8), Hop::Keep(8)] + Hops::from(vec![ + Hop::Keep(32), + Hop::Keep(32), + Hop::Keep(8), + Hop::Keep(8) + ]) ); assert_eq!( neighbors(&asked(r#"{"num_hops": 3}"#), RunMode::Best).unwrap(), - vec![Hop::Keep(64), Hop::Keep(64), Hop::Keep(8)] + Hops::from(vec![Hop::Keep(64), Hop::Keep(64), Hop::Keep(8)]) ); + // Past the six sizes a mode lists, each hop keeps the last. + let eight = fast(r#"{"num_hops": 8}"#); + let sizes: Vec> = (0..9).map(|hop| eight.get(hop).cloned()).collect(); + let mut expected: Vec> = [32, 32, 8, 8, 4, 4, 4, 4] + .iter() + .map(|&n| Some(Hop::Keep(n))) + .collect(); + expected.push(None); + assert_eq!(sizes, expected); + // A count far past any graph is read lazily, never laid out. + let far = fast(r#"{"num_hops": 100000000000000000000000000000000000000000}"#); + assert_eq!(far.get(1_000_000), Some(&Hop::Keep(4))); // num_hops named as none, with no num_neighbors, is the engine's // TypeError: the caller's. let e = neighbors(&asked(r#"{"num_hops": null}"#), RunMode::Fast).unwrap_err(); @@ -1963,7 +1989,7 @@ mod tests { let given = asked(r#"{"num_neighbors": [5, 1, 0, 3], "num_hops": 2}"#); assert_eq!( neighbors(&given, RunMode::Fast).unwrap(), - vec![Hop::Keep(5), Hop::Keep(1), Hop::Stop, Hop::Keep(3)] + Hops::from(vec![Hop::Keep(5), Hop::Keep(1), Hop::Stop, Hop::Keep(3)]) ); // Numeric bounds keep their sign; caller text retains its origin // for capability-driven warehouse lookback arithmetic. @@ -1986,19 +2012,19 @@ mod tests { RunMode::Fast ) .unwrap(), - vec![Hop::Keep(4), wanted], + Hops::from(vec![Hop::Keep(4), wanted]), ); } assert_eq!(hops_ignored(&given), None); let wide = asked(r#"{"num_neighbors": [100000000000000000000000000000]}"#); assert_eq!( neighbors(&wide, RunMode::Fast).unwrap(), - vec![Hop::Keep(u64::MAX)] + Hops::from(vec![Hop::Keep(u64::MAX)]) ); let odd = asked(r#"{"num_neighbors": [2.0, 2.5, true, false, 0.5, -0.0, 0.0, 1e30]}"#); assert_eq!( neighbors(&odd, RunMode::Fast).unwrap(), - vec![ + Hops::from(vec![ Hop::Keep(2), Hop::Keep(2), Hop::Keep(1), @@ -2007,17 +2033,17 @@ mod tests { Hop::Stop, Hop::Stop, Hop::Keep(u64::MAX) - ] + ]) ); let spelled = asked(r#"{"num_neighbors": ["3", "-0", "0", "2.5"]}"#); assert_eq!( neighbors(&spelled, RunMode::Fast).unwrap(), - vec![Hop::Keep(3), Hop::Keep(0), Hop::Keep(0), Hop::Keep(2)] + Hops::from(vec![Hop::Keep(3), Hop::Keep(0), Hop::Keep(0), Hop::Keep(2)]) ); let spaced = asked(r#"{"num_neighbors": [" 3 ", "1e1", ".5"]}"#); assert_eq!( neighbors(&spaced, RunMode::Fast).unwrap(), - vec![Hop::Keep(3), Hop::Keep(10), Hop::Keep(0)] + Hops::from(vec![Hop::Keep(3), Hop::Keep(10), Hop::Keep(0)]) ); for size in ["null", "[1]"] { let e = neighbors( @@ -2037,7 +2063,7 @@ mod tests { ); assert_eq!( neighbors(&values, RunMode::Fast).unwrap(), - vec![ + Hops::from(vec![ Hop::Negative(sdm_contract::data::NegativeNeighborBound::new("-1".into()).unwrap()), Hop::Negative( sdm_contract::data::NegativeNeighborBound::new("-0.5".into()).unwrap() @@ -2046,7 +2072,7 @@ mod tests { Hop::Expression("3 OR TRUE".into()), Hop::Expression("nonsense".into()), Hop::Keep(u64::MAX), - ] + ]) ); } diff --git a/rust/crates/sdm-request/src/payload.rs b/rust/crates/sdm-request/src/payload.rs index dff2002d4..821132ec6 100644 --- a/rust/crates/sdm-request/src/payload.rs +++ b/rust/crates/sdm-request/src/payload.rs @@ -79,11 +79,6 @@ pub const RESERVED: [&str; 2] = [INSTANCE_ID, ANCHOR_TIME]; const NO_ANCHOR: i64 = -9_223_372_036_854_775_807; /// The largest integer a JSON number carries exactly in every reader. const JSON_SAFE: i128 = 9_007_199_254_740_991; -/// The largest payload the endpoint takes, in bytes (`_MAX_SIZE`), counted -/// as the bytes the payload is written as and sent, UTF-8 (register PD-2), -/// not the reference's `json.dumps` count, which escapes every character -/// past ASCII. -pub const PAYLOAD_BYTES: usize = 30 * 1024 * 1024; /// One column of a sampled table: as sampled, or a text feature as the /// reference's sampler sends it, each value its words @@ -219,11 +214,6 @@ pub struct Sampled { /// How many candidates the call asked be kept (`top_k`), written into /// the task as the engine writes it. pub top_k: Option, - /// The most rows any call of the request this payload is one call of - /// scores (`_the_largest_batch`, `main`'s multi-call `predict`): the - /// size a refusal of a payload past the endpoint's limit names as the - /// one to ask below. - pub rows_per_call: usize, /// The lagged target columns (`lag_timesteps`), in order; none /// where the call asks for none. pub lags: Vec, @@ -1440,17 +1430,6 @@ fn build_mode( num_prediction_examples: sampled.num_test as u64, }; let model = "kumo-relational".to_owned(); - // Only this small state-only member is counted separately; never copy or - // reparse the potentially 30MiB table data merely to measure its wire size. - let client_only_bytes = if client_generated_keys.is_empty() { - 0 - } else { - serde_json::to_vec(&client_generated_keys) - .expect("string map serializes") - .len() - + br#""client_generated_keys":"#.len() - + 1 // comma separating the member from model-facing members - }; let bytes = if link.is_some() { StatePayload { client_analysis_delta: None, @@ -1511,42 +1490,6 @@ fn build_mode( } .to_bytes() }; - // The limit counts the bytes the request sends, as written (PD-2). - // The refusal names what to change, as the reference's client words - // its engine's (`_said_in_this_client_s_terms`, `main`'s 1fc5a686): a - // call scoring several rows can be asked as smaller calls, below the - // most rows a call of the request scores (`smaller_calls`); a call of - // one row cannot, and only a narrower context helps - // (`no_smaller_call`). - let model_bytes = bytes.len() - client_only_bytes; - if model_bytes > PAYLOAD_BYTES { - let count = |n: usize| Detail::Scalar(sdm_contract::Scalar::UInt64(n as u64)); - return Err(CoreError::new( - if sampled.num_test > 1 { - Sentence::PayloadSmallerCalls - } else { - Sentence::PayloadNoSmallerCall - }, - "the request is larger than the endpoint takes", - ) - .with_field("field", Detail::text("payload")) - .with_field("bytes", count(model_bytes)) - .with_field("limit", count(PAYLOAD_BYTES)) - .with_field( - "batch_too_large_to_send", - Detail::Scalar(sdm_contract::Scalar::Bool(true)), - ) - .with_field( - "remedy", - Detail::text(if sampled.num_test > 1 { - "smaller_calls" - } else { - "no_smaller_call" - }), - ) - .with_field("rows", count(sampled.num_test)) - .with_field("rows_per_call", count(sampled.rows_per_call))); - } Ok(Built { bytes, answering: answered.len(), diff --git a/rust/crates/sdm-request/src/predict.rs b/rust/crates/sdm-request/src/predict.rs index 7e74e5583..4e670d9c5 100644 --- a/rust/crates/sdm-request/src/predict.rs +++ b/rust/crates/sdm-request/src/predict.rs @@ -93,8 +93,9 @@ pub const INFERENCE_OPTIONS: [&str; 6] = [ /// The most classes `kumo-relational` classifies (`classes_max`). pub const CLASSES_MAX: usize = 10; -/// The most context rows `kumo-relational` reads (`context_rows_max`). -pub const CONTEXT_ROWS_MAX: usize = 10_000; +/// The context rows a single-table request is sampled to where the caller +/// names no `num_context_samples` (`context_rows_max`): a default, not a cap. +pub const CONTEXT_ROWS_DEFAULT: usize = 10_000; /// The context the mode that explains takes at most (`context_rows_fast`). pub const CONTEXT_ROWS_FAST: usize = 1_000; @@ -334,12 +335,6 @@ fn instance_table<'a>(payload: &'a Value, half: &str) -> Option<(Vec<&'a str>, & (names.len() == columns.len()).then_some((names, rows.as_slice())) } -/// The rows of one half, counted as `Request._rows` counts them: none -/// where the half cannot be read. -fn rows_of(payload: &Value, half: &str) -> usize { - instance_table(payload, half).map_or(0, |(_, rows)| rows.len()) -} - /// The rows one call scores (`_envelope_rows(payload, 'predict')`): its /// predict half's rows, none where the half cannot be read. pub fn predict_rows(payload: &Value) -> Option { @@ -471,12 +466,6 @@ pub fn prepare( }); check_shapes(spec, kind, anchored, linked, tables)?; check_task_outputs(spec, kind, &outputs, true)?; - let rows = payloads - .iter() - .map(|p| rows_of(p, "context")) - .max() - .unwrap_or(0); - check_capacity(spec, rows, false)?; if spec.id == TABULAR { // The tabular model takes no relational request this build sends. return Err(not_yet("model")); @@ -877,27 +866,6 @@ fn is_chosen(value: &Value) -> bool { } } -/// The bytes of the call `body` writes, as the host sends them, unchanged: -/// refused past the endpoint's limit (`PAYLOAD_BYTES`), counted on these -/// bytes, the envelope included, which are the bytes sent (register PD-2, -/// fix round 1), before the model is called. -pub fn call_bytes(call: &Value) -> Result, CoreError> { - let bytes = call.to_bytes(); - if bytes.len() > crate::payload::PAYLOAD_BYTES { - return Err(CoreError::new( - Sentence::CallPastEndpoint, - "the call is larger than the endpoint takes", - ) - .with_field("field", Detail::text("call")) - .with_field("bytes", Detail::Scalar(Scalar::UInt64(bytes.len() as u64))) - .with_field( - "limit", - Detail::Scalar(Scalar::UInt64(crate::payload::PAYLOAD_BYTES as u64)), - )); - } - Ok(bytes) -} - /// The entity a row is about, as the result gives it: as the reference's /// `as_declared` reads its value back as the key's dtype, or as written /// where it does not read or no dtype is known. @@ -2351,23 +2319,6 @@ fn check_task_outputs( } Ok(()) } -fn check_capacity(spec: &Spec, rows: usize, direct: bool) -> Result<(), CoreError> { - if (direct || spec.id == RELATIONAL) && rows > CONTEXT_ROWS_MAX { - return Err(unsupported( - if direct { - Sentence::DirectContextLimit - } else { - Sentence::ContextPastModel - }, - spec.id, - "the request's context is larger than the model reads", - ) - .with_field("context_rows", count(rows)) - .with_field("context_rows_max", count(CONTEXT_ROWS_MAX))); - } - Ok(()) -} - /// Model preflight for live direct request facts, before conversion or empty handling. pub fn bind_direct( input: sdm_contract::direct::DirectCallFacts, @@ -2404,7 +2355,6 @@ pub fn bind_direct( input.tables, )?; check_task_outputs(spec, &input.kind, &outputs, false)?; - check_capacity(spec, input.context_rows, true)?; Ok(sdm_contract::direct::BoundDirectCall { facts, model: input.model, diff --git a/rust/crates/sdm-request/src/tabular.rs b/rust/crates/sdm-request/src/tabular.rs index f05c38be9..8bcdddafb 100644 --- a/rust/crates/sdm-request/src/tabular.rs +++ b/rust/crates/sdm-request/src/tabular.rs @@ -1243,13 +1243,3 @@ pub fn decide_materialized_task( }, } } - -/// Select the cap refusal from a reached native comparison, without coercing -/// its original count owner or reading the candidate frame population. -pub fn check_materialized_cap( - input: sdm_contract::tabular::CheckTabularCap, -) -> sdm_contract::tabular::CheckedTabularCap { - sdm_contract::tabular::CheckedTabularCap { - accepted: !input.over_limit, - } -} diff --git a/rust/crates/sdm-request/tests/batch_limits.rs b/rust/crates/sdm-request/tests/batch_limits.rs index 4c32f6645..cbaa053b8 100644 --- a/rust/crates/sdm-request/tests/batch_limits.rs +++ b/rust/crates/sdm-request/tests/batch_limits.rs @@ -5,36 +5,16 @@ use sdm_request::options::{BatchTask, rows_one_call_scores, rows_one_task_call_scores}; #[test] -fn temporal_links_cannot_raise_the_model_limit() { - for (asked, expected) in [ - (None, 200), - (Some(100), 100), - (Some(199), 199), - (Some(200), 200), - (Some(201), 200), - (Some(1000), 200), - (Some(u64::MAX), 200), +fn each_task_batches_by_its_default_and_the_size_asked_is_taken_as_is() { + for (task, default) in [ + (BatchTask::TemporalLink, 200), + (BatchTask::Ordinary, 10_000), ] { - assert_eq!( - rows_one_task_call_scores(asked, BatchTask::TemporalLink), - expected - ); - } -} - -#[test] -fn ordinary_and_decomposed_tasks_keep_their_existing_limit() { - for (asked, expected) in [ - (None, 10_000), - (Some(100), 100), - (Some(201), 201), - (Some(1000), 1000), - (Some(u64::MAX), 10_000), - ] { - assert_eq!( - rows_one_task_call_scores(asked, BatchTask::Ordinary), - expected - ); - assert_eq!(rows_one_call_scores(asked), expected); + assert_eq!(rows_one_task_call_scores(None, task), default); + for asked in [1, 100, 20_000, u64::MAX] { + assert_eq!(rows_one_task_call_scores(Some(asked), task), asked); + } } + assert_eq!(rows_one_call_scores(None), 10_000); + assert_eq!(rows_one_call_scores(Some(50_000)), 50_000); } diff --git a/rust/crates/sdm-request/tests/payload_bytes.rs b/rust/crates/sdm-request/tests/payload_bytes.rs deleted file mode 100644 index 3b34a3390..000000000 --- a/rust/crates/sdm-request/tests/payload_bytes.rs +++ /dev/null @@ -1,119 +0,0 @@ -// SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. -// All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -//! The payload limit counts the bytes the request sends (register PD-2, -//! ): the builder's UTF-8 bytes, as written, so a payload of exactly -//! the limit is taken and one byte more refused, where the reference -//! counted `json.dumps`' text, which writes each character past ASCII as a -//! six-byte escape. Held at the limit with ASCII text and with text of two-, -//! three- and four-byte characters, which the reference's count would -//! have taken for three to twelve times its size. - -use std::sync::Arc; - -use arrow_array::{ArrayRef, Int64Array, StringArray}; -use sdm_contract::ErrorCode; -use sdm_contract::ops::Stype; -use sdm_engine::labels::Labels; -use sdm_request::options::{Kind, Options, RunMode}; -use sdm_request::payload::{PAYLOAD_BYTES, Sampled, SampledColumn, SampledTable, build}; - -const ANCHOR: i64 = 1_709_251_200_000_000_000; - -/// One entity, one context example and one to predict, each carrying -/// `note` as a categorical text feature. -fn sampled(note: &str) -> Sampled { - let column = |a: ArrayRef| SampledColumn::Arrow(a); - Sampled { - num_train: 1, - num_test: 1, - anchors: vec![ANCHOR, ANCHOR], - kind: Kind::Regression, - labels: Labels::Float(vec![1.0]), - windowed: true, - tables: vec![SampledTable { - name: "users".into(), - primary_key: Some("user_id".into()), - batch: vec![0, 1], - columns: vec![ - ( - "user_id".into(), - column(Arc::new(Int64Array::from(vec![0, 1]))), - ), - ( - "note".into(), - column(Arc::new(StringArray::from(vec![note, note]))), - ), - ], - stypes: vec![("note".into(), Stype::Categorical)], - }], - links: vec![], - entity_table: "users".into(), - source_query: String::new(), - run_mode: RunMode::Fast, - use_prediction_time: false, - return_embeddings: false, - options: Options::default(), - statistic: None, - top_k: None, - rows_per_call: 1, - lags: vec![], - float_text: |x| format!("{x:?}"), - } -} - -/// The payload's length with `n` copies of `unit` in each note. -fn length(unit: &str, n: usize) -> Result { - build(&sampled(&unit.repeat(n))) - .map(|built| built.bytes.len()) - .map_err(|e| e.code) -} - -#[test] -fn the_limit_counts_the_bytes_sent_at_the_limit() { - for unit in ["a", "\u{e9}", "\u{20ac}", "\u{1f600}"] { - let width = unit.len(); - // Each note is written twice (the context's row and the predicted - // row), so the payload grows by twice a unit's bytes per unit. - let base = length(unit, 0).unwrap(); - let step = length(unit, 1).unwrap() - base; - assert_eq!(step, 2 * width, "{unit:?}"); - // The most units whose payload is within the limit, and the slack - // left, which ASCII padding of the bytes that remain fills. - let n = (PAYLOAD_BYTES - base) / step; - let slack = PAYLOAD_BYTES - base - n * step; - let at = format!("{}{}", unit.repeat(n), "a".repeat(slack / 2)); - let taken = build(&sampled(&at)).expect("a payload within the limit is taken"); - let exact = base + n * step + 2 * (slack / 2); - assert_eq!(taken.bytes.len(), exact, "{unit:?}"); - assert!(exact <= PAYLOAD_BYTES && PAYLOAD_BYTES - exact <= 1); - // The bytes counted are the bytes written: UTF-8, each character - // its own bytes, not an escape. - let text = String::from_utf8(taken.bytes.clone()).unwrap(); - assert!(!text.contains("\\u"), "{unit:?}"); - // Two units more (four bytes or more past it) are refused, as the - // reference refuses a payload past its limit. - let past = format!("{}{}", unit.repeat(n + 2), "a".repeat(slack / 2)); - let refused = build(&sampled(&past)).expect_err("a payload past the limit"); - assert_eq!(refused.code, ErrorCode::InvalidRequest, "{unit:?}"); - } - // With ASCII the payload reaches the limit exactly, one byte step past - // it refused: the count is of bytes, to the byte. - let base = length("a", 0).unwrap(); - let fill = |extra: usize| { - let half = (PAYLOAD_BYTES - base + extra) / 2; - build(&sampled(&"a".repeat(half))) - }; - let even = (PAYLOAD_BYTES - base).is_multiple_of(2); - let at = fill(0).expect("at the limit"); - assert_eq!( - at.bytes.len(), - if even { - PAYLOAD_BYTES - } else { - PAYLOAD_BYTES - 1 - } - ); - assert_eq!(fill(2).unwrap_err().code, ErrorCode::InvalidRequest); -} diff --git a/rust/crates/sdm-request/tests/payload_lock.rs b/rust/crates/sdm-request/tests/payload_lock.rs index 72da4d2ed..06ebb7e9b 100644 --- a/rust/crates/sdm-request/tests/payload_lock.rs +++ b/rust/crates/sdm-request/tests/payload_lock.rs @@ -56,7 +56,6 @@ fn shop() -> Sampled { options: Options::default(), statistic: Some("mean".into()), top_k: None, - rows_per_call: 1, lags: vec![], float_text: |x| format!("{x:?}"), tables: vec![ @@ -140,7 +139,6 @@ fn family() -> Sampled { options: Options::default(), statistic: None, top_k: None, - rows_per_call: 1, lags: vec![], float_text: |x| format!("{x:?}"), tables: vec![ @@ -191,7 +189,6 @@ fn classified(kind: Kind, labels: Labels) -> Sampled { windowed: false, statistic: None, top_k: None, - rows_per_call: 1, lags: vec![], ..shop() } diff --git a/rust/crates/sdm-testkit/src/host.rs b/rust/crates/sdm-testkit/src/host.rs index 722c21124..72afe4f7d 100644 --- a/rust/crates/sdm-testkit/src/host.rs +++ b/rust/crates/sdm-testkit/src/host.rs @@ -1794,8 +1794,6 @@ fn start_materialize( values: Some(AttachmentId(6)), options: vec![], most_parts: None, - most_entities: None, - most_calls: None, sampler_state: sampler .as_ref() .and_then(|held| held.as_ref()) diff --git a/rust/crates/sdm-testkit/tests/payload_rules.rs b/rust/crates/sdm-testkit/tests/payload_rules.rs index d6eb3d80d..f7bcecfac 100644 --- a/rust/crates/sdm-testkit/tests/payload_rules.rs +++ b/rust/crates/sdm-testkit/tests/payload_rules.rs @@ -171,8 +171,9 @@ fn multiclass_labels_and_leakage_match_source_entities() { } #[test] -fn more_entities_than_one_materialize_holds_are_refused_by_its_limit() { - // Missing IDs and the public materialization limit are distinct refusals. +fn no_entity_count_is_refused_by_a_limit() { + // The core holds a materialize to no entity count. Ids the base does + // not hold are refused for that reason, at 1,001 and at 100,001 alike. let with = |n: u64| { let (mut case, bases) = the_case("base.regression"); let materialize = case @@ -185,26 +186,12 @@ fn more_entities_than_one_materialize_holds_are_refused_by_its_limit() { .collect(); host::run(&case, &bases).unwrap() }; - let observed = with(1001); - let Answer::Error { code, fields, .. } = &observed.answer else { - panic!("not refused: {:?}", observed.answer); - }; - assert_eq!(code, "INVALID_REQUEST"); - assert_eq!(fields.get("field").map(String::as_str), Some("indices")); - // Past 100,000 the core's own limit refuses them before anything is - // read, naming it (`most_entities`), not a rule it does not hold yet. - let observed = with(100_001); - assert!( - observed.materialized.is_none(), - "100,001 entities were taken" - ); - let Answer::Error { code, fields, .. } = &observed.answer else { - panic!("not refused: {:?}", observed.answer); - }; - assert_eq!(code, "UNSUPPORTED_REQUEST"); - assert_eq!( - fields.get("rule").map(String::as_str), - Some("most_entities") - ); - assert_eq!(fields.get("field").map(String::as_str), Some("indices")); + for n in [1001, 100_001] { + let observed = with(n); + let Answer::Error { code, fields, .. } = &observed.answer else { + panic!("not refused: {:?}", observed.answer); + }; + assert_eq!(code, "INVALID_REQUEST", "{n}"); + assert_eq!(fields.get("field").map(String::as_str), Some("indices")); + } } diff --git a/rust/crates/sdm-testkit/tests/payload_shape_validation.rs b/rust/crates/sdm-testkit/tests/payload_shape_validation.rs index 3238ffd55..f61e7ce8f 100644 --- a/rust/crates/sdm-testkit/tests/payload_shape_validation.rs +++ b/rust/crates/sdm-testkit/tests/payload_shape_validation.rs @@ -166,6 +166,14 @@ fn payloads() -> Vec<(String, Value)> { { continue; } + // The size boundaries materialize in full now that the client holds + // a request to no size, and carry no shape the others do not. + if one.case.id.starts_with("multicall.body-30mib.") + || one.case.id == "multicall.calls.101" + || one.case.id == "multicall.entities.100001" + { + continue; + } let observed = host::run(&one.case, &bases).unwrap(); if let Some(state) = observed.materialized { found.push((one.case.id.clone(), numbers(state["payload"].clone()))); diff --git a/skills/relational/SKILL.md b/skills/relational/SKILL.md index 90c6fab1c..c857efa46 100644 --- a/skills/relational/SKILL.md +++ b/skills/relational/SKILL.md @@ -150,37 +150,28 @@ views, and a notebook's own session are in ## Which rows get scored -`materialize(indices=[...])` names the entities. It gathers each one's -neighbourhood, checks every limit before sending, and refuses with the limit it -would break rather than letting the endpoint return a 500. +`materialize(indices=[...])` names the entities and gathers each one's +neighbourhood. The client holds a request to no size of its own: a request +past what the endpoint takes is the endpoint's refusal, shown as it said it. | Limit | Value | |---|---| | context rows, by default | `1,000` | -| context rows, with `num_context_samples` | `10,000` | -| rows scored at once | `10,000` | -| tables in the gathered graph | `15` | -| hops gathered | `6` | | classes | `10` | -**More rows than one call scores are not refused.** They are gathered in -batches of at most that many, and `predict()` sends one call per batch and -returns one result, whose rows are numbered across the whole request, so -`to_pandas()` gives the indices back in the order they were asked for. The -10,000 is the deployment's `TFM_MAX_TEST_ROWS`, not a property of the -protocol; pass `rows_per_call=` to ask in smaller batches, which is what a -graph too wide for a full one needs. It only goes down. - -Every batch is built before the first is sent, so one `materialize()` gathers -at most 100,000 entities, in at most 100 calls. Both are this client's own: -the endpoint is never asked for more than one call holds. A question asked +**Rows are scored in batches.** They are gathered in batches of 10,000, and +`predict()` sends one call per batch and returns one result, whose rows are +numbered across the whole request, so `to_pandas()` gives the indices back in +the order they were asked for. Pass `rows_per_call=` to ask in batches of +another size. + +Every batch is built before the first is sent, each with its own context, so +the whole population is held in memory at once. A question asked in parts is not batched at all: a ranking is already a call per candidate and a forecast one per step, and batching a part would send that many times as many calls. -**The table limit is on the graph a request carries, not on the schema.** A -schema may describe far more than fifteen tables; what counts is how many the -query actually reaches. +The gathered graph may carry any number of tables; sampling supports at most six hops. Gradient explanations follow the model endpoint's supported outputs; the client does not impose a separate one-row or fast-context limit. ## Asking for more than one answer each @@ -298,8 +289,6 @@ change. The ones worth knowing: |---|---| | every candidate's context holds one class | each gathered entity reached it, or none did, so there is nothing to tell apart and nothing is sent; widen with `num_context_samples` or ask over a table of pairs. One such candidate among several is dropped with a warning instead, and named on `result.unscored_candidates` | | no entity existed at the anchor | the entity table's time column starts after the anchor, so nothing existed to ask about | -| more than 100,000 entities at once | every batch is built before any is sent; ask about fewer at a time | -| more than 100 calls at once | a context is gathered per call; ask about fewer entities, or raise `rows_per_call` if you lowered it | | more entities than one call scores, on a ranking or a forecast | each candidate or step is already a call, and batching one would send that many times as many; ask about fewer at a time | | an output this question cannot give | `rankings` on a regression, `explanation` on a client-assembled ranking | | `422 UNSUPPORTED_OUTPUT` | the client sent an output the deployment does not serve, such as `explanation` | diff --git a/skills/tabular/SKILL.md b/skills/tabular/SKILL.md index f4b921b5b..734a2ad1b 100644 --- a/skills/tabular/SKILL.md +++ b/skills/tabular/SKILL.md @@ -34,7 +34,6 @@ with SDMClient(url='http://localhost:8000') as client: | Relationships | no | | Explanations | yes | | Sessions | yes | -| Context rows | 10,000 | Anything outside that list belongs to the relational model. Asking for `rankings` or a forecast here is refused before a request @@ -136,8 +135,8 @@ guesses that way and names the argument that settles it. ## Which rows get scored `Request(context=..., predict=...)` takes two frames and sends exactly those -rows. It trims neither. A context above 10,000 rows is refused with the count -and the cap rather than quietly dropping rows you named. +rows. It trims neither, and holds the context to no size of its own: a +context larger than the endpoint takes is the endpoint's refusal. The rows to score need not appear in the labelled half, and usually should not: they are the rows whose answer you do not have. @@ -183,8 +182,8 @@ print(answer.to_pandas()) ``` Twenty rows in, three named, and `request.context_rows` is 17: the scored rows -are held out of their own context. `materialize()` also samples down to the -10,000-row cap. +are held out of their own context. `materialize()` also samples the context +to 10,000 rows unless you pass `num_context_samples`. On this model the language is cut down to a column of one table as the target: no aggregation, no window, no comparison, no forecast, no ranking, no entity @@ -241,7 +240,6 @@ names what to change. |---|---| | a task the model does not serve | `forecasting` and the rest are relational; no released model serves `temporal_link_prediction` | | an output it does not produce | `rankings`, `embeddings`, `scores` | -| a context above the cap | more than 10,000 labelled rows in a direct `Request` | | relationships | this model reads one table; use `kumo-relational` | Catch `StructuredDataError` to catch all of them. diff --git a/tests/compatibility/manifest.json b/tests/compatibility/manifest.json index f335f4491..856d432d8 100644 --- a/tests/compatibility/manifest.json +++ b/tests/compatibility/manifest.json @@ -4630,8 +4630,7 @@ "packages/structured-data-models-client/tests/test_envelope_and_result.py::test_explain_default_outputs_names_missing_structured_gradient_step", "packages/structured-data-models-client/tests/test_runtime_ownership.py::test_installed_explanations_has_one_origin_and_no_retired_dependencies", "packages/structured-data-models-client/tests/test_relational_explanations.py::test_explain_one_class_refusal_names_source_column", - "packages/structured-data-models-client/tests/test_tabular_explanations.py::test_empty_explanation_view_retains_columns", - "packages/structured-data-models-client/tests/test_payload_rules.py::test_client_only_provenance_does_not_consume_model_payload_limit" + "packages/structured-data-models-client/tests/test_tabular_explanations.py::test_empty_explanation_view_retains_columns" ], "java": [ "java/src/test/java/com/nvidia/sdm/GradientExplanationsTest.java#publicGradientCollectionSurvivesNestedMergesAndSessions", @@ -8293,6 +8292,16 @@ "base_commit": "a441e59a7dfb507185a11e3d157cd762529c9e40", "record": "type_contracts/arrow-admission-and-inference", "reason": "Fixture cleanup removes unused historical observation/provenance fields. All 110 vector IDs and every retained type, witness, admission and inference fact remain unchanged; update the whole-file checksum and reference the renamed test that checks actual runtime refusals instead of recorded expectations." + }, + { + "base_commit": "868363fd938dd37b46fac62578d13922f83f91a8", + "record": "api_contracts/gradient-explanations", + "reason": "The client no longer enforces the endpoint's payload size limit, so the test that client-only provenance does not count toward that limit was removed with it; the remaining gradient tests are unchanged." + }, + { + "base_commit": "8c9d723c9f6ecff8c2f6f4d6d5357af17ea4399e", + "record": "api_contracts/gradient-explanations", + "reason": "The client no longer enforces the endpoint's payload size limit, so the test that client-only provenance does not count toward that limit was removed with it; the remaining gradient tests are unchanged." } ], "capabilities": [ diff --git a/tests/test_skills.py b/tests/test_skills.py index 36336fbe8..19a45436b 100644 --- a/tests/test_skills.py +++ b/tests/test_skills.py @@ -2231,10 +2231,7 @@ def test_the_capability_table_is_the_clients_own(name, model_name): 'Sessions': capabilities.sessions, } if name == 'tabular': - from sdm_client.models import TABULAR_LIMITS - said['Explanations'] = 'explanation' in capabilities.outputs - said['Context rows'] = TABULAR_LIMITS['context_rows_max'] assert set(shown) == set(said), ( f'{name} shows rows nothing checks: {sorted(set(shown) ^ set(said))}' ) @@ -2264,10 +2261,6 @@ def test_the_capability_table_is_the_clients_own(name, model_name): #: and a row naming no limit is a number nobody is holding to anything. LIMIT_ROWS = { 'context rows, by default': 'context_rows_fast', - 'context rows, with `num_context_samples`': 'context_rows_max', - 'rows scored at once': 'predict_rows_max', - 'tables in the gathered graph': 'tables_max', - 'hops gathered': 'hops_max', 'classes': 'classes_max', }