Skip to content

refactor: llguidance - #288

Merged
guicho271828 merged 10 commits into
generative-computing:mainfrom
guicho271828:llguidance
Feb 12, 2026
Merged

guicho271828 merged 10 commits into
generative-computing:mainfrom
guicho271828:llguidance

Conversation

@guicho271828

Copy link
Copy Markdown
Contributor

No description provided.

@mergify

mergify Bot commented Jan 6, 2026 •

Copy link
Copy Markdown

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert|release)(?:\(.+\))?:

@guicho271828 guicho271828 changed the title Llguidance refactor: llguidance Jan 6, 2026

@jakelorocco jakelorocco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's some mypy errors as well.

Comment thread mellea/backends/vllm.py Resolved
Comment thread mellea/backends/vllm.py Resolved
Comment thread mellea/backends/huggingface.py Resolved
@guicho271828

Copy link
Copy Markdown
Contributor Author

Looks like there's some mypy errors as well.

I don't know why there is a mypy error. Mypy passes locally for me.

@guicho271828
guicho271828 force-pushed the llguidance branch 2 times, most recently from 3ebb8bd to 8dce1f2 Compare January 7, 2026 19:29
@nrfulton

nrfulton commented Jan 7, 2026

Copy link
Copy Markdown
Member

Looks like there's some mypy errors as well.

I don't know why there is a mypy error. Mypy passes locally for me.

We've seen this happen recently and it came down to mypy versions. Could be the cause. I re-ran the checks on the latest branch. If those still fail and you still pass with mypy, try checking your mypy version.

@guicho271828

Copy link
Copy Markdown
Contributor Author

With an updated lockfile the mypy passes. Test is terminated but locally it is passing. If you approve, I will merge this

@jakelorocco jakelorocco left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@guicho271828, can you remind me if we ever got the local vllm backend running on mac (or if you remember a discussion about that)?

I tried installing this version of the mellea package on my mac and was getting versioning errors.

Details

(mellea) ➜  mellea git:(pr/guicho271828/288) uv pip install -e '.[all]' --all-extras --group dev -r pyproject.toml
Using Python 3.12.0 environment at: /opt/homebrew/Caskroom/miniforge/base/envs/mellea
  × No solution found when resolving dependencies:
  ╰─▶ Because only the following versions of nvidia-cudnn-frontend are available:
          nvidia-cudnn-frontend<=1.13.0
          nvidia-cudnn-frontend==1.14.0
          nvidia-cudnn-frontend==1.14.1
          nvidia-cudnn-frontend==1.15.0
          nvidia-cudnn-frontend==1.16.0
          nvidia-cudnn-frontend==1.17.0
      and nvidia-cudnn-frontend>=1.13.0 has no wheels with a matching platform tag (e.g., `macosx_15_0_arm64`), we can conclude that
      nvidia-cudnn-frontend>=1.13.0 cannot be used.
      And because flashinfer-python==0.5.3 depends on nvidia-cudnn-frontend>=1.13.0 and vllm==0.13.0 depends on flashinfer-python==0.5.3, we
      can conclude that vllm==0.13.0 cannot be used.
      And because only vllm<=0.13.0 is available and mellea depends on vllm>=0.13.0, we can conclude that your requirements are
      unsatisfiable.

It looks like the newest version I can install on a mac is 0.11.0.

The vllm engine can't seem to get enough resources to run locally on my mac anyways, so maybe we can just add a note somewhere that "mella[vllm]" doesn't work for macs?

@guicho271828

Copy link
Copy Markdown
Contributor Author

@guicho271828, can you remind me if we ever got the local vllm backend running on mac (or if you remember a discussion about that)?

I tried installing this version of the mellea package on my mac and was getting versioning errors.
Details

The vllm engine can't seem to get enough resources to run locally on my mac anyways, so maybe we can just add a note somewhere that "mella[vllm]" doesn't work for macs?

To run vllm locally, vllm assumes

NVIDIA GPUs, AMD CPUs and GPUs, Intel CPUs and GPUs, PowerPC CPUs, and TPU

So yes mella[vllm] does not work on Mac.

@guicho271828

Copy link
Copy Markdown
Contributor Author

@guicho271828, can you remind me if we ever got the local vllm backend running on mac (or if you remember a discussion about that)?

I tried installing this version of the mellea package on my mac and was getting versioning errors.
Details

(mellea) ➜  mellea git:(pr/guicho271828/288) uv pip install -e '.[all]' --all-extras --group dev -r pyproject.toml
Using Python 3.12.0 environment at: /opt/homebrew/Caskroom/miniforge/base/envs/mellea
  × No solution found when resolving dependencies:
  ╰─▶ Because only the following versions of nvidia-cudnn-frontend are available:
          nvidia-cudnn-frontend<=1.13.0
          nvidia-cudnn-frontend==1.14.0
          nvidia-cudnn-frontend==1.14.1
          nvidia-cudnn-frontend==1.15.0
          nvidia-cudnn-frontend==1.16.0
          nvidia-cudnn-frontend==1.17.0
      and nvidia-cudnn-frontend>=1.13.0 has no wheels with a matching platform tag (e.g., `macosx_15_0_arm64`), we can conclude that
      nvidia-cudnn-frontend>=1.13.0 cannot be used.
      And because flashinfer-python==0.5.3 depends on nvidia-cudnn-frontend>=1.13.0 and vllm==0.13.0 depends on flashinfer-python==0.5.3, we
      can conclude that vllm==0.13.0 cannot be used.
      And because only vllm<=0.13.0 is available and mellea depends on vllm>=0.13.0, we can conclude that your requirements are
      unsatisfiable.

It looks like the newest version I can install on a mac is 0.11.0.

The vllm engine can't seem to get enough resources to run locally on my mac anyways, so maybe we can just add a note somewhere that "mella[vllm]" doesn't work for macs?

29588fb disables installing vllm on darwin.

Comment thread mellea/backends/vllm.py Resolved
Comment thread test/backends/test_vllm_tools.py Resolved
@guicho271828
guicho271828 force-pushed the llguidance branch 4 times, most recently from 27a9159 to 91a9e1a Compare February 11, 2026 13:25

@jakelorocco jakelorocco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also confirm that the huggingface / vllm tests run with the most recent changes.

Comment thread test/backends/test_huggingface.py Resolved
Comment thread test/backends/test_huggingface_tools.py Resolved
Comment thread docs/kv_smash/kvcache.py
device = torch.device("mps")
model = AutoModelForCausalLM.from_pretrained(model_id).to(device)
model = AutoModelForCausalLM.from_pretrained(model_id)
# model = model.to(device=device) # this part does not pass mypy; possible misconfiguration

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code does not pass mypy and this error existed from before, it is not written by me.
Annoyingly, without fixing this, I cannot commit any changes with pre-commit enabled, especially because now all code in docs/ are also checked by pre-commit.

Comment thread mellea/core/backend.py Resolved
@guicho271828
guicho271828 force-pushed the llguidance branch 3 times, most recently from d3c9044 to 81ee868 Compare February 11, 2026 22:44
@guicho271828

guicho271828 commented Feb 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Two huggingface tests failed which are out of scope of this PR.

FAILED test/backends/test_huggingface.py::test_format - AssertionError: The email address should be at example.com

-> structured output failure due to a weak model

FAILED test/backends/test_huggingface.py::test_error_during_generate_with_lock - AssertionError: Regex pattern did not match.

-> test for error handling, discussed in #432
-> this must be addressed in all backends

One vllm test failed.

FAILED test/backends/test_vllm.py::test_generate_from_raw_with_format - AssertionError: formatting directive failed for {

-> structured output failure due to a weak model

@jakelorocco jakelorocco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@guicho271828
guicho271828 added this pull request to the merge queue Feb 12, 2026
Merged via the queue into generative-computing:main with commit 6205b36 Feb 12, 2026
4 checks passed
@guicho271828
guicho271828 deleted the llguidance branch February 12, 2026 19:33
akihikokuroda pushed a commit to akihikokuroda/mellea that referenced this pull request May 27, 2026
* fix(conda): conda should not always supersede mamba

* fix(conda): fixed existing conda environment detection; fails if there is any env name with "mellea"

* refactor: outlines -> llguidance on vllm/hf, vllm 0.13, V1 API, disable vllm on osx

* fix: revert BaseModelSubclass default value

* fix: removed unused Generic from ReactInitiator

* fix(docs): pass docs/kv_smash/kvcache.py

* fixup! fix: revert BaseModelSubclass default value

* fixup! refactor: outlines -> llguidance on vllm/hf, vllm 0.13, V1 API, disable vllm on osx

* fixup! refactor: outlines -> llguidance on vllm/hf, vllm 0.13, V1 API, disable vllm on osx

* fixup! refactor: outlines -> llguidance on vllm/hf, vllm 0.13, V1 API, disable vllm on osx
planetf1 added a commit to planetf1/mellea that referenced this pull request Aug 7, 2026
… calls

With whitespace_flexible=False (compact JSON), llguidance constructs a grammar
where the highest-probability token after opening an array '[' is immediately
']', silently collapsing structured output to empty arrays (e.g.
{"result":[]}) under greedy decoding.  No exception is raised and the caller
cannot distinguish a correct empty list from a grammar-induced collapse.

This bug was introduced in PR generative-computing#288 as a mechanical outlines->llguidance port.
The llguidance library's own default for whitespace_flexible is True; the
original False was never intentional.

Fix all three grammar_from_json_schema call sites in LocalHFBackend:
- _generate_from_context_with_kv_cache
- _generate_from_context_standard
- _generate_from_raw

Regression tests added for all three call sites (mock-based, no real model).

Fixes generative-computing#1510

Assisted-by: IBM Bob
Signed-off-by: Nigel Jones <[email protected]>
jakelorocco pushed a commit to jakelorocco/mellea that referenced this pull request Aug 13, 2026
…prevent silent array collapse (generative-computing#1513)

* fix(hf): set whitespace_flexible=True in all grammar_from_json_schema calls

With whitespace_flexible=False (compact JSON), llguidance constructs a grammar
where the highest-probability token after opening an array '[' is immediately
']', silently collapsing structured output to empty arrays (e.g.
{"result":[]}) under greedy decoding.  No exception is raised and the caller
cannot distinguish a correct empty list from a grammar-induced collapse.

This bug was introduced in PR generative-computing#288 as a mechanical outlines->llguidance port.
The llguidance library's own default for whitespace_flexible is True; the
original False was never intentional.

Fix all three grammar_from_json_schema call sites in LocalHFBackend:
- _generate_from_context_with_kv_cache
- _generate_from_context_standard
- _generate_from_raw

Regression tests added for all three call sites (mock-based, no real model).

Fixes generative-computing#1510

Assisted-by: IBM Bob
Signed-off-by: Nigel Jones <[email protected]>

* fix(hf): address reviewer feedback on generative-computing#1513

- Rewrite regression tests to model each method's actual async control
  flow instead of swallowing exceptions with a silent try/except.
- Hoist the llguidance grammar defaults into a module constant typed
  as JsonCompileOptions (imported under TYPE_CHECKING from the private
  llguidance._lib submodule, since it isn't re-exported publicly) to
  keep mypy accurate without resorting to Any.
- Remove dead mock setup (allocate_token_bitmask, unused LLMatcher
  return value) left over from the old test scaffolding.
- Document the whitespace_flexible=True token overhead in the HF
  integration guide.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* fix(hf): also set whitespace_flexible=True in the m serve grammar call

The chat_completion_request_to_transformers_inputs() grammar_from_json_schema()
call (the OpenAI-compatible /chat/completions path used by m serve) omitted
defaults entirely. JsonCompileOptions.whitespace_flexible's docstring claims it
"defaults to true" when omitted, but empirically it does not: omitting defaults
produces no explicit whitespace_flexible setting at all, and falls through to
the underlying JsonCompiler's real default of False -- so this call site was
exposed to the same generative-computing#1510 collapse bug as the three already-fixed call sites in
LocalHFBackend.

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* fix(hf): correct whitespace_flexible defeatability and dedupe constant

- overrides= instead of defaults= at the m serve grammar call site, since
  its schema comes straight off the wire and a caller could otherwise embed
  x-guidance.whitespace_flexible=false to defeat a defaults= pass
- move _LLGUIDANCE_GRAMMAR_DEFAULTS to util.py as the single definition,
  imported by huggingface.py instead of duplicated
- correct util.py comment: llguidance's own default is already True when
  defaults is omitted, so the m serve call site was never affected by generative-computing#1510
- fix test mock signature regression from the overrides= swap, and a stale
  test comment
- reword docs token-overhead note to match

Assisted-by: Claude Code
Signed-off-by: Nigel Jones <[email protected]>

* fix(hf): set bounded whitespace_pattern to prevent silent array collapse and runaway spaces

Address review feedback from Jake LoRocco on generative-computing#1513. Replacing whitespace_flexible: True with a bounded whitespace_pattern: r"[\x20\x0A\x0D\x09]{0,20}". This allows spaced/pretty JSON (preventing the silent array collapse bug generative-computing#1510) and safely accommodates 4-space indentation up to 4 levels of nesting, while establishing an absolute hard limit of 20 consecutive characters of whitespace to completely prevent infinite or runaway whitespace generation.

Assisted-by: IBM Bob
Signed-off-by: Nigel Jones <[email protected]>

* docs(hf): update huggingface documentation for bounded whitespace_pattern

Assisted-by: IBM Bob
Signed-off-by: Nigel Jones <[email protected]>

---------

Signed-off-by: Nigel Jones <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants