-
Notifications
You must be signed in to change notification settings - Fork 413
update snippets for image-text-to-text models for transformers models #1434
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
Changes from 8 commits
47a4f2f
ce932fe
43cd1a4
d10b418
cf220d4
b1ced46
16da5b3
72e5212
9266c59
4773dbd
9004d0c
5f9ed87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1119,13 +1119,27 @@ export const transformers = (model: ModelData): string[] => { | |
if (model.pipeline_tag && LIBRARY_TASK_MAPPING.transformers?.includes(model.pipeline_tag)) { | ||
const pipelineSnippet = ["# Use a pipeline as a high-level helper", "from transformers import pipeline", ""]; | ||
|
||
if (model.tags.includes("conversational") && model.config?.tokenizer_config?.chat_template) { | ||
pipelineSnippet.push("messages = [", ' {"role": "user", "content": "Who are you?"},', "]"); | ||
if (model.config?.tokenizer_config?.chat_template) { | ||
if (model.tags.includes("conversational") && model.tags.includes("image-text-to-text")) { | ||
pipelineSnippet.push( | ||
"messages = [", | ||
[ | ||
" {", | ||
' "role": "user",', | ||
' "content": [', | ||
' {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"},', | ||
' {"type": "text", "text": "What animal is on the candy?"}', | ||
" ]", | ||
" },", | ||
].join("\n"), | ||
"]" | ||
); | ||
} else if (model.tags.includes("conversational")) { | ||
Vaibhavs10 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pipelineSnippet.push("messages = [", ' {"role": "user", "content": "Who are you?"},', "]"); | ||
} | ||
} | ||
pipelineSnippet.push(`pipe = pipeline("${model.pipeline_tag}", model="${model.id}"` + remote_code_snippet + ")"); | ||
if (model.tags.includes("conversational") && model.config?.tokenizer_config?.chat_template) { | ||
pipelineSnippet.push("pipe(messages)"); | ||
} | ||
pipelineSnippet.push("pipe(messages)"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm, I think this line is still out of the conversational path. How about something like this? (forgive mistakes, typing in this text box)
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It isn't no? https://gist.github.com/Vaibhavs10/b525c1ae4982c04fe0202c2f78ac2f03 the pipeline instantiation and the pipe(messages) is the same for both (my JS sucks so could very well be a skill issue) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. I suggested another variation based on your previous comments here: https://gist.github.com/Vaibhavs10/b525c1ae4982c04fe0202c2f78ac2f03?permalink_comment_id=5569573#gistcomment-5569573 Changes are:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm stupid for not looking at that code block - sorry for being so dense! |
||
|
||
return [pipelineSnippet.join("\n"), autoSnippet]; | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.