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

Role blocks fail silently inside of stateless grammars #916

Open
hudson-ai opened this issue Jun 20, 2024 · 6 comments
Open

Role blocks fail silently inside of stateless grammars #916

hudson-ai opened this issue Jun 20, 2024 · 6 comments

Comments

@hudson-ai
Copy link
Collaborator

The bug
Role blocks fail silently inside of stateless grammars -- I think it's okay if they are only supported in stateful contexts, but the user should get an error.

To Reproduce

import guidance
@guidance(stateless=True)
def foo(lm):
    with guidance.user():
        lm += "hello!"
    return lm
model = guidance.models.Mock()
model += foo()
str(model)
>> `hello!`

System info (please complete the following information):

  • OS (e.g. Ubuntu, Windows 11, Mac OS, etc.): Windows 11
  • Guidance Version (guidance.__version__): 0.1.15
@hudson-ai
Copy link
Collaborator Author

Same with the block context manager. I know that this may be impossible to implement with the current design for these context managers, but it's worth thinking about.

@Harsha-Nori
Copy link
Collaborator

wow great catch, had no idea these were failing!

@hudson-ai
Copy link
Collaborator Author

@nking-1 and I were deep in the trenches yesterday 😂

@nking-1
Copy link
Contributor

nking-1 commented Jun 22, 2024

@hudson-ai do you remember where the root cause of the bug was? Is it in __add__() in model.py?

@hudson-ai
Copy link
Collaborator Author

It's sort of inherent to the implementation of context blocks. Opening/closing them just adds/removes something from a class-level dict on Model that affects the __add__ method on Model instances.

The problem is that we never hit that __add__ inside of stateless grammars, because no Model instances ever gets passed to the function. They are "compiled" by passing an empty string in the lm slot of the signature.

A workaround may be to send an instance of a "fake" Model subclass through rather than the empty string, but I think it may honestly be worth taking this opportunity to rethink the context managers a bit.

@michael-newsrx
Copy link

See also: #786 (comment)

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

No branches or pull requests

4 participants