-
Notifications
You must be signed in to change notification settings - Fork 225
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
Update conversational widget to use text-generation (+ remove conversational
task)
#457
Conversation
(my first commits just fixed some of the dependencies to Let me try to answer (or at least provide discussion for) your questions:
We'll get this PR ready before merging https://github.com/huggingface/moon-landing/issues/8578, and then hopefully there should be no "transition period" (each text-generation model will be assigned a conversational or text-generation widget). Sure, there might be issues with compatibility, but we'll add some checks to default back to previous functionality if something is missing (like
The way transformers.js handles this, is that (like the transformers library) we define the default chat templates associated for each model type (e.g., here for llama). If no chat_template is found and the user tries to run
This is most likely due to an outdated tokenizer_config.json (like this), but is also possible if the model doesn't have a tokenizer_config.json. Fortunately, when saving newer tokenizers, the required special tokens are saved. However, in cases where something is not defined, we can either (1) use pre-defined defaults, or (2) disable the widget, or (3) default to text-generation.
I think we will need to convert it to the ChatML format (JSON array of messages, each with at least |
We also need to decide how users should define system prompts/messages. This might be something we need to pass in from the yaml in the model card (i.e., in the same way as examples are specified) |
.../src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte
Outdated
Show resolved
Hide resolved
packages/widgets/src/lib/components/InferenceWidget/InferenceWidget.svelte
Outdated
Show resolved
Hide resolved
packages/widgets/src/lib/components/InferenceWidget/InferenceWidget.svelte
Outdated
Show resolved
Hide resolved
# TL;DR - Update `text-generation` spec to match TGI API - ~Add `conversational` spec, heavily inspired by TGI messages API (cc @Wauplin @osanseviero @Narsil )~ - ~Relevant related work: #457 & huggingface-internal/moon-landing#8723 - regenerate typescript code for those tasks
…b.com:huggingface/huggingface.js into 8578-switch-conversational-to-text-generation
I've updated this PR with feedback and improved the logic to handle chat format. cc @julien-c @osanseviero I have also merged work from #479 that will remove the |
.../src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte
Outdated
Show resolved
Hide resolved
model.pipeline_tag && model.pipeline_tag in WIDGET_COMPONENTS | ||
? WIDGET_COMPONENTS[model.pipeline_tag as keyof typeof WIDGET_COMPONENTS] | ||
: undefined; | ||
model.pipeline_tag === "text-generation" && model.tags?.includes("conversational") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also model.pipeline_tag === text2text-generation
btw @osanseviero no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed imo. https://huggingface.co/models?pipeline_tag=text2text-generation&other=conversational&sort=trending only has 29 models and they don't have templates (vs 9300 public models in https://huggingface.co/models?pipeline_tag=text-generation&other=conversational&sort=trending )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(also moot if we merge text2text-generation into text-generation like i'd like to 😁)
.../src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking nice!
|
||
## Useful Resources | ||
|
||
- Learn how ChatGPT and InstructGPT work in this blog: [Illustrating Reinforcement Learning from Human Feedback (RLHF)](https://huggingface.co/blog/rlhf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI @merveenoyan as we'll want to move some of this to text-generation
task page
model.pipeline_tag && model.pipeline_tag in WIDGET_COMPONENTS | ||
? WIDGET_COMPONENTS[model.pipeline_tag as keyof typeof WIDGET_COMPONENTS] | ||
: undefined; | ||
model.pipeline_tag === "text-generation" && model.tags?.includes("conversational") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed imo. https://huggingface.co/models?pipeline_tag=text2text-generation&other=conversational&sort=trending only has 29 models and they don't have templates (vs 9300 public models in https://huggingface.co/models?pipeline_tag=text-generation&other=conversational&sort=trending )
.../src/lib/components/InferenceWidget/widgets/ConversationalWidget/ConversationalWidget.svelte
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool stuff 🔥
I also just added some error checking to the compilation and render steps of the chat template: Invalid chat templatesThe error message is supplied by Valid template, but error during runtime(To test, I just deleted Finally, I updated it so that we only add message on first call (not also if model loading response received). Otherwise we get: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't approve my own PR but I reviewed @xenova last changes. Thanks for making the extra step ❤️ Everything looks good for a merge now :)
Will merge it on tomorrow if no-one complains until then (not sure anymore who should/want to review it one more time 😄 )
🚀 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on my side i'll check in prod 🙂
And... finally merged! 😄 🚀 |
input: string; | ||
response: string; | ||
export let messages: Array<{ | ||
role: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we make the typing even stronger here?
role: "user" | "assistant" | "system"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
following #457 (comment) cc @mishig25 --------- Co-authored-by: Simon Brandeis <[email protected]>
Done as part of https://github.com/huggingface/moon-landing/issues/8578. Should be merged before (or at the same time) as https://github.com/huggingface/moon-landing/pull/8723. This is only a first draft to check if we have everything we need.
From https://github.com/huggingface/moon-landing/issues/8578:
Currently in this PR:
ConversationalWidget
will call thetext-generation
API under the hood. (automatic in inference API ifpipeline_tag
gets updated by https://github.com/huggingface/moon-landing/pull/8723)cc @xenova @osanseviero @SBrandeis @coyotte508
Still unsure how to proceed:
chat_template
? => EDIT: raise errorchat_template
but noeos_token
/bos_token
? => EDIT: should be okConversation
structure in the widget (withgenerated_responses
/past_user_inputs
/generated_text
) ? If not, would need more svelte expertise 😄 => EDIT: ok