RRobin PicardAdd the credit_card custom type
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
fix: raise clearly instead of asserting on a rejected XGrammar token XGrammarLogitsProcessor.process_logits used `assert self._matchers[i].accept_token(last_token_id)` to advance the grammar matcher's state after each generated token. Python's `-O`/ `PYTHONOPTIMIZE=1` mode strips all `assert` statements at compile time, so under that mode the matcher's state is silently never advanced past the first token: no error, no warning, and structured-output constraints (regex/JSON-schema/CFG) stop being enforced for the rest of generation. Replace the assert with an explicit check that raises RuntimeError, which -O cannot strip. Added a unit test constructing the processor with a mocked rejecting matcher, confirming a clear RuntimeError is raised. Verified it fails (AssertionError under normal mode, would silently no-op under -O) against the pre-fix code and passes after -- including re-running it under `python -O` directly to confirm the fix is optimization-safe. Ran the full tests/backends/test_xgrammar.py suite (4 passed, 1 skipped for non-Apple-Silicon) and pre-commit (mypy + ruff) clean. Disclosure: I used an AI coding assistant (Claude) to help identify this bug and draft the fix. I independently reproduced the AssertionError pre-fix, verified the fix under both normal and `-O` execution modes, and ran the full local backend test suite before opening this PR. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> | 1 个月前 | |
Update CFGGuide to use outlines.fsm.parsing. Enable generate.cfg | 1 年前 | |
fix(sglang): copy caller extra_body before merging structured outputs _pop("extra_body", {}) returns the caller's dict when present, so .update() leaked structured_outputs/regex into subsequent unconstrained calls. Mirror the VLLM fix (#1933) with dict(...). Fixes #1931 | 1 个月前 | |
fix(processors): NumpyTensorAdapter.apply_mask doesn't broadcast a lower-rank mask like torch's masked_fill apply_mask used boolean fancy-index assignment (`result[mask] = value`), which requires the mask's shape to exactly match the tensor's shape -- numpy raises IndexError instead of broadcasting when the shapes only match under normal broadcasting rules (e.g. a 1D mask applied to a 2D tensor, a common pattern for reusing the same per-token mask across every row of a batch). TorchTensorAdapter.apply_mask already uses torch.masked_fill, and MLXTensorAdapter already uses mlx.where, both of which broadcast correctly. Only the numpy adapter lacked this, making numpy-backed generation crash on a mask shape that works fine on the other two backends. Fix: use numpy.where(mask, value, tensor), matching MLX's approach and torch's masked_fill's broadcasting semantics. Also non-mutating (like masked_fill), unlike the previous copy-then-index-assign, which is a behavior improvement consistent with the other two adapters. Added test_tensor_adapter_apply_mask_broadcasts_lower_rank_mask (parametrized across all three frameworks) using a 1D mask against a 2D tensor. TDD red->green verified: reverting only numpy.py reproduces `IndexError: boolean index did not match indexed array along axis 0`; reapplying passes. Full tests/processors/test_tensor_adapters.py: 24 passed, 12 skipped (MLX unavailable in this environment, pre-existing and unrelated). ruff/mypy clean via pre-commit. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> | 1 个月前 | |
Mock tests for LMStudio | 7 个月前 | |
Add the credit_card custom type Add a credit_card type to outlines.types matching payment card numbers for the common networks (Visa, Mastercard, American Express, Diners Club, Discover, JCB, Maestro and UnionPay) by issuer prefix and length. It validates the number format only, not the Luhn digit, so constraining generation to a card number no longer needs a hand-written regex. | 1 个月前 | |
Add interactive execution mode Since execution can take some time we would like to display current progress to the user. We use the `rich` library to show live updates as the program is being executed. | 3 年前 | |
Fix `vllm`-related pytest warning (that was spaming user) Before this commit, when you ran pytest -k specific_test, it spawned dozens of the same skipped warnings message on stdout... IMHO, that was not ideal ^^ Bug introduced in d32dfde3ae7eac71f57af96d5141975ef9322b12 | 1 年前 | |
Improve docstrings and type hinting in model base and generator | 1 年前 | |
Upgrade outlines_core to 0.2.11 and update its logits processor/backend | 1 年前 | |
fix(exceptions): don't require a provider's optional SDK to normalize errors `is_provider_exception` and `normalize_provider_exception` are public API (both exported in `__all__`). Their documented contract is to let non-provider errors pass through untouched and otherwise fall back to HTTP status-code inspection. `_build_exception_map` broke that contract: for every provider except `mistral` it did a bare `import openai` / `import anthropic` / etc. When the named provider's optional SDK was not installed, building the map raised `ModuleNotFoundError` instead of degrading gracefully. So calling `is_provider_exception(TypeError(...), "openai")` without the `openai` package installed crashed with an import error that masks the user's original exception. This is reachable whenever a caller uses the public helpers for a provider whose SDK is not the one installed (a common multi-provider / minimal-install setup), and it fires inside the `normalize_provider_errors` context manager too. The `mistral` branch already guarded its optional import with `try/except ImportError`; this makes the other six providers consistent. Fix: split the SDK-dependent body into `_provider_exception_map` and wrap the single call site in `try/except ImportError`, returning an empty map when the SDK is absent. Callers then fall through to the SDK-free status-code inspection, which is unchanged. Behavior when the SDK *is* installed is identical. Evidence: 13 existing tests in `test_exceptions.py` (`TestIsProviderException`, `TestNormalizeProviderErrors`) already fail when `openai` is not installed, because they deliberately test with synthetic errors and do not `importorskip` (unlike the sibling `TestExceptionMap*` classes, which correctly do). Those 13 now pass. Added `TestProviderSDKNotInstalled`: parametrized over all providers, it blocks each optional import via `sys.modules[name] = None` so the missing -SDK path is exercised deterministically even in CI where every SDK is installed. The new tests fail without this fix and pass with it. | 2 个月前 | |
Update generator tests to match modified vllm server interface | 2 个月前 | |
Update docstring with OpenAI’s multi-modal chat format support, and update tests to verify new functionality for multimodal chat | 11 个月前 | |
Render Optional enum/nested fields in the schema filter | 1 个月前 |