Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set additionalProperties boolean on JSON schema #116

Open
stodoran opened this issue Dec 6, 2024 · 0 comments
Open

Unable to set additionalProperties boolean on JSON schema #116

stodoran opened this issue Dec 6, 2024 · 0 comments
Labels
bug Something isn't working json schema

Comments

@stodoran
Copy link

stodoran commented Dec 6, 2024

Describe the issue as clearly as possible:

According the the JSON schema documentation, an object in a JSON schema can set additionalProperties to false to limit the keys on an object. However this causes an error when using outlines.

I'm using outlines as the guided decoding backend for vLLM.

Steps/code to reproduce the bug:

json_guidance = {
    "type": "object",
    "patternProperties": {
        "^[0-9]+$": {
            "anyOf": [
                {"type": "string"},
                {
                    "type": "object",
                    "properties": {
                        "num_items": {"minimum": 0, "type": "integer"},
                    },
                    "patternProperties": {"^[0-9]+$": {"type": "string"}},
                    "additionalProperties": False,
                },
            ]
        }
    },
    "additionalProperties": False,
}

guided_decoding_params = GuidedDecodingParams(json=json_guidance, backend="outlines")
sampling_params = SamplingParams(temperature=0.0, max_tokens=max_decoding_length, logprobs=1, guided_decoding=guided_decoding_params)
model_response = self.model.generate(llm_inputs, sampling_params, use_tqdm=False)

Expected result:

Expectation is that generation would succeed.

Error message:

Call stack Traceback (most recent call last):
File "/data1/predict.py", line 288, in _generate_vllm
    model_response = self.model.generate(llm_inputs, sampling_params, use_tqdm=False)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/utils.py", line 1063, in inner
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/entrypoints/llm.py", line 398, in generate
    self._validate_and_add_requests(
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/entrypoints/llm.py", line 875, in _validate_and_add_requests
    self._add_request(
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/entrypoints/llm.py", line 893, in _add_request
    self.llm_engine.add_request(
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/utils.py", line 1063, in inner
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/engine/llm_engine.py", line 857, in add_request
    self._add_processed_request(
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/engine/llm_engine.py", line 696, in _add_processed_request
    seq_group = self._create_sequence_group_with_sampling(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/engine/llm_engine.py", line 910, in _create_sequence_group_with_sampling
    sampling_params = self._build_logits_processors(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/engine/llm_engine.py", line 2056, in _build_logits_processors
    processor = get_local_guided_decoding_logits_processor(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/model_executor/guided_decoding/__init__.py", line 36, in get_local_guided_decoding_logits_processor
    return get_local_outlines_guided_decoding_logits_processor(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/model_executor/guided_decoding/outlines_decoding.py", line 91, in get_local_outlines_guided_decoding_logits_processor
    return _get_logits_processor(guide, tokenizer, mode,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/model_executor/guided_decoding/outlines_decoding.py", line 127, in _get_logits_processor
    return JSONLogitsProcessor(guide, tokenizer, whitespace_pattern)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/vllm/model_executor/guided_decoding/outlines_logits_processors.py", line 150, in __init__
    regex_string = build_regex_from_schema(schema_str, whitespace_pattern)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/outlines/fsm/json_schema.py", line 86, in build_regex_from_schema
    return to_regex(resolver, content, whitespace_pattern)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/outlines/fsm/json_schema.py", line 451, in to_regex
    value_pattern = to_regex(
                    ^^^^^^^^^
  File "/data1/pyenv/lib/python3.11/site-packages/outlines/fsm/json_schema.py", line 187, in to_regex
    elif "properties" in instance:
         ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'bool' is not iterable

Outlines/Python version information:

Version information

``` outline 0.0.46 vllm 0.6.4.post1 Python 3.11.0rc1 (main, Aug 12 2022, 10:02:14) [GCC 11.2.0] ```

Context for the issue:

This is a pretty serious issue for my use case since the ability to set additionalProperties to false on an object is a pretty foundational feature of a JSON schema.

@stodoran stodoran added the bug Something isn't working label Dec 6, 2024
@rlouf rlouf transferred this issue from dottxt-ai/outlines Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working json schema
Projects
None yet
Development

No branches or pull requests

2 participants