Skip to content
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

Using delegates on a method breaks TypeDispatch #538

Open
warner-benjamin opened this issue Oct 24, 2023 · 1 comment
Open

Using delegates on a method breaks TypeDispatch #538

warner-benjamin opened this issue Oct 24, 2023 · 1 comment

Comments

@warner-benjamin
Copy link
Contributor

Adding a delegates decorator to a method prevents TypeDispatch from creating the correct dispatching table.

Without delegates, the dispatch for TensorAudio.create is correct:

class TensorAudio(TensorBase):
    @classmethod
    def create(cls, fn:str|Path, **kwargs):
        sig, sr = torchaudio.load(fn, **kwargs)
        return cls(sig, sr=sr)

TypeDispatch(TensorAudio.create) returns

(str,object) -> create
(Path,object) -> create

But with delegates, TypeDispatch doesn't create the correct dispatch table:

class TensorAudio(TensorBase):
    @delegates(torchaudio.load)
    @classmethod
    def create(cls, fn:str|Path, **kwargs):
        sig, sr = torchaudio.load(fn, **kwargs)
        return cls(sig, sr=sr)

TypeDispatch(TensorAudio.create)

Instead TypeDispatch(TensorAudio.create) returns:

(str,BinaryIO) -> create
(str,str) -> create
(str,PathLike) -> create
(Path,BinaryIO) -> create
(Path,str) -> create
(Path,PathLike) -> create

The BinaryIO, str, and PathLike in the type dispatch are from torchaudio.load. It's missing (str,object) and (Path,object). This incorrect dispatch prevents from TensorAudio.create dispatching in a fastai datablock.

Previous versions of fastcore did not have this interplay between delegates and TypeDispatch, but I am not sure when it cropped up.

@jph00
Copy link
Member

jph00 commented Apr 26, 2024

Do you want to try fixing this @warner-benjamin ?

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

No branches or pull requests

2 participants