-
Notifications
You must be signed in to change notification settings - Fork 26.7k
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
GenerationConfig throws Object is not JSON serializable when setting constraints #31070
Comments
cc @gante |
I think this error is coming because we are trying to get serialized representation of the constraint object at several places. I think the easy fix would be have a serialization method for constraint class that can be triggered. Can I propose a PR for this? For this, I think we might have to go through all possible class objects that can be consumed by GenerationConfig class, and implement a general purpose serialization mechanism, easiest is to replace class object with @gante I would like to propose a PR but I am not sure what would be ideal approach, would like to get suggestions to move forward. :) Edit: Upon digging a bit deeper, I realized that the error is coming in this function 1055, where we do not explicitly take care of serializing class objects. We can just reimplement this function and it will fix everything. |
This should serialize also the code of my custom defined constraints, I don't see a way of doing this without pickle. |
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
System Info
From the GenerationConfig documentation Constraints should be supported but when I try to load any it fails.
I know I can also set the constraints directly in the
pipeline.generate()
, (*edit: not really a constraint but through the logit_ processor) but for my use case I need to store the constraints in the configuration for later usage.Following code reproduces the issue:
Who can help?
No response
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
from transformers import PhrasalConstraint
from transformers import GenerationConfig
model_name = "deepseek-ai/deepseek-coder-1.3b-base"
tokenizer = AutoTokenizer.from_pretrained(model_name)
stop_token_id = tokenizer("STOP").input_ids
constraint = PhrasalConstraint(stop_token_id)
generation_config, unused_kwargs = GenerationConfig.from_pretrained(
model_name,
constraints=[constraint])
Expected behavior
From documentation it should support Constraints, https://huggingface.co/docs/transformers/en/main_classes/text_generation#transformers.GenerationConfig.constraints, I expect the constraints to be stored somehow and be loaded automatically when calling AutoModelForCausalLM.
The text was updated successfully, but these errors were encountered: