-
Notifications
You must be signed in to change notification settings - Fork 531
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
[Inference Client] Add task parameters and a maintenance script of these parameters #2561
base: main
Are you sure you want to change the base?
Conversation
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 PR will complete some tasks from #2063 :) |
The goal of the script
A first implementation was done using
libCST operates on a tree-like structure that represents the entire source code, including whitespace and comments. Here, we leverage two main concepts:
The script is still experimental and there are known limitations (non-exhaustive):
|
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.
Looks good!
Thanks for the explanations about LibCST. It seems like the right tool to use in our case. Since it's a dev dependency, it's fine adding it. To be honest I did not review the full utils/generate_task_parameters.py
script but I'm pretty confident it does the job. Let's hope it'll not become a nightmare to maintain (same for all utils/
scripts^^). If it starts to be the case, we can always reassess. Updating utils is less stressful given we don't have to think about backward compatibility.
Apart from the comments below, I think it's pretty much ready to merge :)
) -> List[AudioClassificationOutputElement]: | ||
""" | ||
Perform audio classification on the provided audio content. | ||
For more details about the input parameters, see the [pipeline documentation](https://huggingface.co/docs/transformers/en/main_classes/pipelines#transformers.AudioClassificationPipeline). |
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.
I find it a bit confusing to redirect from Inference docs to the transformers
pipeline docs. I feel that we should better document the parameters if that's what's missing here.
Because here for example https://huggingface.co/docs/transformers/en/main_classes/pipelines#transformers.AudioClassificationPipeline.__call__ do not provide any information about function_to_apply
, meaning we would have to maintain both docs. Better not to have this additional "docs dependency".
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.
I added this because for almost all task parameters, the default values are only documented in the pipeline docs, e.g. for text-classification
here
but you're right, it's still an additional doc dependency but it would be nice to have access to the default values in the inference doc.
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.
Yes indeed, we should better document the specs themselves but it will be done in separate PRs 😕
parameters = { | ||
"threshold": threshold, | ||
} | ||
if all(parameter is None for parameter in parameters.values()): | ||
# if no parameters are provided, the image can be raw bytes, an image file, or URL to an online image | ||
data = image | ||
payload: Optional[Dict[str, Any]] = None | ||
else: | ||
# if parameters are provided, the image needs to be a base64-encoded string | ||
data = None | ||
payload = {"inputs": _b64_encode(image)} | ||
for key, value in parameters.items(): | ||
if value is not None: | ||
payload.setdefault("parameters", {})[key] = value |
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.
(out of scope for this PR) I feel that we should factorize the logic to handle inputs
+ parameters
i.e. rules like "base64 encode only if at least 1 parameter", "provide parameters if at least 1 parameter", "provide only not none parameters".
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.
agree!
…ign-inference-inputs-with-specs
@Wauplin do you have an idea why the build of the PR documentation is failing? my guess: private message |
Fixes #2557.
This PR adds the possibility to pass additional parameters to task methods in the inference client, aligning these task methods with their corresponding parameter specs.
Key changes
audio-classification
,document-question-answering
,fill-mask
,image-classification
,image-segmentation
,object-detection
,question-answering
,summarization
,text-classification
,token-classification
,translation
andzero-shot-image-classification
.parameters
argument, inconsistent with task specifications #2557 for related discussion.utils/generate_inference_types.py
to add task-specific prefixes to shared type aliases:ClassificationOutputTransform
toTextClassificationOutputTransform
for text-classification taskutils/
.Note:
automatic-speech-recognition
andimage-to-text
tasks are not included in this update due to an existing parameter naming discrepancy (see issue here).