Skip to content

Conversation

@omkar-334
Copy link
Contributor

@omkar-334 omkar-334 commented Dec 12, 2025

What does this PR do?

Removes requests code from setup, src and utils files.
Fixes #42817 partially

  • Quality checks: make fixup passes with no errors

cc @CoderTCY @Wauplin @Rocketknight1

notes -

  1. I've removed requests from setup/workflow files as well, you might want to check the first commit.
  2. A few formatting fixes like "spacing around operators" got added in as well

@guibruand
Copy link

guibruand commented Dec 15, 2025

Hello, I got some issues with the current port to httpx.
I managed to set up huggingface_hub calls using the set_factory_client() with my custom httpx Client, and it would be nice if all httpx sessions in transformers rely on the same mechanism.

One way to do it would be for example:


from huggingface_hub import get_session

client = get_session()
result = client.post(....)

This also concerns some other portions of code (like safetensors_conversion.py).
Thank you for your support.

@Wauplin
Copy link
Contributor

Wauplin commented Dec 19, 2025

Agree with @guibruand 's suggestion here! It's best to use huggingface_hub.get_session and then deal with the returned Client as if it was httpx directly. @omkar-334 would you like to give it a try? 🙏

@omkar-334
Copy link
Contributor Author

Agree with @guibruand 's suggestion here! It's best to use huggingface_hub.get_session and then deal with the returned Client as if it was httpx directly. @omkar-334 would you like to give it a try? 🙏

Got it. I'll try using that and let you know!

@Wauplin
Copy link
Contributor

Wauplin commented Dec 19, 2025

Thank you very much! 🤗

@omkar-334
Copy link
Contributor Author

omkar-334 commented Dec 20, 2025

Hey @Wauplin , so I've used get_session instead of using httpx directly.
I've called the function once and reused it in the file. Is this appropriate, or should we call get_session for each request?
As far as i know, the get_session already manages a global client and returns it right?

Thanks

Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @omkar-334 , thanks for the changes and sorry for the delay before reviewing. I'm very sorry about my previous comment regarding get_session. I should have more carefully double-checked the changes and context before answering. It turns out most (if not all) changes made in the PR would better benefit from using httpx directly for simplicity rather than huggingface_hub.get_session.

While get_session is better suited to make requests to the Hub (it has HF-specific features), plain httpx is better suited for generic cases that are not HF-related. Also, let's use httpx in all 1-file scripts and utilities (since they are mostly meant for devs/maintainers rather than end users).

Sorry again about this change of direction 🙏

import requests
import tensorflow as tf
import torch
from huggingface_hub import get_session
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above (and sorry not being explicit before). For single-file scripts I think it's best to keep it as lean as possible, i.e. use httpx directly as replacement of requests.

get_session is useful when calling the Hub. It adds features to handle request ids and manage offline mode. When in doubt you can use get_session but otherwise keep httpx for light calls to "generic endpoints" (like here, loading an image from the internet).

@omkar-334
Copy link
Contributor Author

omkar-334 commented Jan 9, 2026

hey @Wauplin , went through your comments, understood the changes i need to make. Thanks for clarifying this.
Just to be sure, this is what we want -

  • get_session - HF hub specific requests

  • httpx - single-file scripts, utilities, examples, local/generic endpoint, convert scripts, loading images

Will make the changes and push soon...
Thanks!

@github-actions
Copy link
Contributor

github-actions bot commented Jan 9, 2026

[For maintainers] Suggested jobs to run (before merge)

run-slow: align, beit, bit, blip, blip_2, chameleon, clipseg, conditional_detr, convnext, convnextv2, d_fine, deformable_detr, deit, depth_anything, detr, dinov2

@omkar-334
Copy link
Contributor Author

omkar-334 commented Jan 9, 2026

hey @Wauplin , I've made the changes.

  1. Currently there are only 6 instances where get_session is used - and they are all images hosted on HF. is this alright or revert these to httpx too?
  2. Also, in src/transformers/safetensors_conversion.py, what should be used? Currently, httpx is used for this url - "https://safetensors-convert.hf.space"
  3. There are a few docstrings where requests is used. Since the docs are user-facing, should i let this be as it is, or change it to httpx as well?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove unnessary requests module

3 participants