Skip to content

Create FetchConfig for standardizing use of fetch#2828

Merged
pplantinga merged 132 commits into
speechbrain:developfrom
pplantinga:allow-network-flag
Jun 3, 2025
Merged

Create FetchConfig for standardizing use of fetch#2828
pplantinga merged 132 commits into
speechbrain:developfrom
pplantinga:allow-network-flag

Conversation

@pplantinga

@pplantinga pplantinga commented Feb 14, 2025

Copy link
Copy Markdown
Collaborator

Code for calling fetch uses a variety of subsets of the actual available options for fetch. This simplifies and standardizes the use of fetch by putting the configuration options in a single place, a FetchConfig dataclass. This should probably sit in develop for awhile before releasing a new version to ensure nothing is broken.

This PR also makes fetch multiprocessing-safe (and therefore save to use with DDP).

@pplantinga pplantinga self-assigned this Feb 14, 2025
@pplantinga pplantinga added refactor Edit code without changing functionality enhancement New feature or request labels Feb 14, 2025
@pplantinga pplantinga added this to the v1.1.0 milestone Feb 14, 2025
@Adel-Moumen

Copy link
Copy Markdown
Collaborator

Wondering about this PR. Are you aware of any other place external to the speechbrain codebase that are using the fetch function? I am thinking of potentially custom Hf interfaces or google colab tutorials that might need to accommodate the new changes.

Comment thread speechbrain/utils/parameter_transfer.py Outdated
rogiervd and others added 20 commits June 2, 2025 14:12
…mbridge) (speechbrain#2913)

Co-authored-by: Rogier van Dalen <r.vandalen@samsung.com>
…#2914)

Co-authored-by: Rogier van Dalen <r.vandalen@samsung.com>
Co-authored-by: Rogier van Dalen <r.vandalen@samsung.com>
…e) (speechbrain#2915)

Co-authored-by: Rogier van Dalen <r.vandalen@samsung.com>
Co-authored-by: Rogier van Dalen <r.vandalen@samsung.com>
Co-authored-by: Rogier van Dalen <r.vandalen@samsung.com>
…n#2911)

Co-authored-by: Rogier van Dalen <r.vandalen@samsung.com>
…ter, Cambridge) (speechbrain#2894)

Co-authored-by: Rogier van Dalen <r.vandalen@samsung.com>
Co-authored-by: Adel Moumen <88119391+Adel-Moumen@users.noreply.github.com>
Co-authored-by: Rogier van Dalen <r.vandalen@samsung.com>
Co-authored-by: Peter Plantinga <plantinga.peter@protonmail.com>
Co-authored-by: Parcollet Titouan <parcollet.titouan@gmail.com>
…rain#2782)

Co-authored-by: Adel Moumen <adelmoumen.pro@gmail.com>
Co-authored-by: Adel Moumen <adelmoumen.pro@gmail.com>
Co-authored-by: Titouan Parcollet <parcollet.titouan@gmail.com>
… Center Cambridge) (speechbrain#2765)

Co-authored-by: Shucong Zhang/Embedded AI /SRUK/Engineer/Samsung Electronics <s1.zhang@sruk-ccn4.eu.corp.samsungelectronics.net>
Co-authored-by: Parcollet Titouan <parcollet.titouan@gmail.com>
@pplantinga pplantinga requested a review from Adel-Moumen June 2, 2025 18:28
Comment thread speechbrain/inference/interfaces.py Outdated
Comment thread speechbrain/inference/interfaces.py Outdated
huggingface_cache_dir=None,
local_strategy: LocalStrategy = LocalStrategy.SYMLINK,
local_strategy=LocalStrategy.SYMLINK,
fetch_config=FetchConfig(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we are again using FetchConfig() as a default value. Can't we just set it to None and if it is None, then init FetchConfig() ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I wonder if I should use a NamedTuple here? This is immutable so we don't have to worry about default values, but it might not play as nicely with type hints if we're going to add those.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Or, perhaps even better is to use frozen=True

https://docs.python.org/3/library/dataclasses.html#frozen-instances

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, with frozen=True it makes it immutable. I guess that if we don't plan to have mutable arguments in FetchConfig, we can just set it as a default value for fetch_config. Otherwise, if we really want to be safe (but I don't think this is really necessary), we can just do fetch_config: Optional[FetchConfig] = None and:

if fetch_config is None:
        fetch_config = FetchConfig()

Both are fine, but fetch_config=FetchConfig() is a bit more idiomatic so we can leave this like that:)

Comment thread speechbrain/inference/interfaces.py Outdated
Comment thread speechbrain/inference/interfaces.py
Comment thread speechbrain/inference/interfaces.py Outdated
Comment thread speechbrain/inference/interfaces.py
Comment thread speechbrain/inference/interfaces.py Outdated

@Adel-Moumen Adel-Moumen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

Quick question: is there a way to tests these functions and make sure they do what they are intended to do?

@pplantinga

pplantinga commented Jun 3, 2025 via email

Copy link
Copy Markdown
Collaborator Author

@pplantinga pplantinga linked an issue Jun 3, 2025 that may be closed by this pull request
@pplantinga pplantinga merged commit 4f4b49c into speechbrain:develop Jun 3, 2025
5 checks passed
@pplantinga pplantinga deleted the allow-network-flag branch June 3, 2025 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request refactor Edit code without changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make fetch DDP-safe