fix(types): improve type hints for mlx_lm.utils.load method#919
fix(types): improve type hints for mlx_lm.utils.load method#919rahuliyer95 wants to merge 3 commits intoml-explore:mainfrom
mlx_lm.utils.load method#919Conversation
|
Thanks but it seems unnecessary. Also would prefer not to reorder the positions of the arguments just in case... |
I understand the concern about reordering the positions of the arguments, but using |
|
Hmm.. ok fair enough. Will you update the PR to use the old ordering and then we can merge it? |
|
Just to be clear, mypy complains because the return type is a It feels like the issue is not in mlx-lm and even though the Wdyt @rahuliyer95 ? |
Yes that's correct.
I believe the benefit is high because without this every consumer of mlx-lm would have to have a check in their code which can be avoided with this overload. Here is some prior art I found for other libraries like Tranformers, PyTorch which do the same. |
Problem
The mlx_lm.utils.load returns a
Tuple[nn.Module, TokenizerWrapper]whenreturn_config=FalseandTuple[nn.Module, TokenizerWrapper, Dict[str, Any]]whenreturn_config=True. Since the return type is controlled by a function argument, the types can improved to determine the correct return type based on the value ofreturn_config.Solution
We can use the
@overloaddecroator to help provide the proper type hints to the callers based on the value ofreturn_config.