Draft
Conversation
Member
Author
|
For potential reviewers: this is very much a draft and hasn't been tested. It is mainly here for discussion to see whether this is something we would like to pursue, and, if so, if you have any specific thoughts regarding how we'd want to approach it. Thank you! |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR offers a new, Agentic surface for transformers. It tries to apply what is done elsewhere with CLIs to
transformers, leveraging many current use-cases oftransformersand exposing them as CLI endpoints.I recommend reading this first: https://github.com/huggingface/transformers/blob/agent-first-cli/src/transformers/cli/agentic/README.md
In my eyes, the advantage is twofold:
transformers. Instead of relying on the docs, understanding our pipelines and their limitation, or working with Python scripts andtransformersprimitives, we're offering single, dedicated entry-points for each relevant task.This is a draft for discussion; If we want to move forward, there are some interesting ways to leverage this:
Example commands:
Text Inference
Classify text into categories (supervised)
transformers classify --model distilbert/distilbert-base-uncased-finetuned-sst-2-english --text "Great movie!"Classify text into arbitrary categories without training (zero-shot)
Extract named entities from text (NER)
transformers ner --model dslim/bert-base-NER --text "Apple CEO Tim Cook met with President Biden in Washington."Tag tokens with labels (POS tagging, chunking)
transformers token-classify --model vblagoje/bert-english-uncased-finetuned-pos --text "The cat sat on the mat."[...]
Text Generation
Generate text from a prompt
transformers generate --model meta-llama/Llama-3.2-1B-Instruct --prompt "Once upon a time"Stream text generation token-by-token
transformers generate --model meta-llama/Llama-3.2-1B-Instruct --prompt "Hello" --streamGenerate with sampling (temperature, top-p, top-k)
transformers generate --prompt "The future of AI" --temperature 0.7 --top-p 0.9Generate with beam search
transformers generate --prompt "Translate this:" --num-beams 4Run speculative decoding with a draft model
transformers generate --model meta-llama/Llama-3.1-8B-Instruct --assistant-model meta-llama/Llama-3.2-1B-Instruct --prompt "Explain gravity."[...]
Vision
Classify an image into categories
Classify an image into arbitrary categories without training (zero-shot)
transformers image-classify --model google/siglip-base-patch16-224 --image photo.jpg --labels "cat,dog,bird,fish"Detect objects in an image with bounding boxes
[...]
Audio
Transcribe speech to text
Transcribe speech with word-level timestamps
transformers transcribe --model openai/whisper-small --audio recording.wav --timestamps true --jsonClassify an audio clip into categories
[...]
Video
[...]
Multimodal
Answer a question about an image (visual QA)
transformers vqa --model vikhyatk/moondream2 --image chart.png --question "What is the trend shown?"Answer a question about a document image (document QA)
transformers document-qa --model impira/layoutlm-document-qa --image invoice.png --question "What is the total amount?"Generate a caption for an image