Proposal: Add mypy to .pre-commit-config.yml
So far, the.pre-commit-config.yml file only calls black and isort. I unintentionally used https://github.pie.apple.com/aiml-oss/ml-recurrent-drafter/blob/main/.pre-commit-config.yaml and discovered the issues addressed in #827 and #828. It may be worthwhile to include mypy and other tools in the above pre-commit configuration.
I think its a good idea, especially if we are going to use type annotations (which we do).
- [ ] gguf_llm/generate.py
- [ ] gguf_llm/models.py
- [ ] llama/convert.py
- [ ] mistral/convert.py
- [ ] mixtral/convert.py
- [ ] mixtral/mixtral.py
- [ ] mlx_lm/lora.py
- [ ] mlx_lm/merge.py
- [ ] mlx_lm/models/cohere.py
- [ ] mlx_lm/models/dbrx.py
- [ ] mlx_lm/models/gemma.py
- [ ] mlx_lm/models/gpt2.py
- [ ] mlx_lm/models/gpt_bigcode.py
- [ ] mlx_lm/models/internlm2.py
- [ ] mlx_lm/models/llama.py
- [ ] mlx_lm/models/minicpm.py
- [ ] mlx_lm/models/mixtral.py
- [ ] mlx_lm/models/olmo.py
- [ ] mlx_lm/models/openelm.py
- [x] mlx_lm/models/phi3.py https://github.com/ml-explore/mlx-examples/pull/833
- [x] mlx_lm/models/phi3small.py https://github.com/ml-explore/mlx-examples/pull/833
- [ ] mlx_lm/models/plamo.py
- [ ] mlx_lm/models/qwen2.py https://github.com/ml-explore/mlx-examples/pull/835
- [ ] mlx_lm/models/qwen2_moe.py https://github.com/ml-explore/mlx-examples/pull/835
- [ ] mlx_lm/models/starcoder2.py https://github.com/ml-explore/mlx-examples/pull/835
- [ ] mlx_lm/server.py
- [ ] mlx_lm/tuner/trainer.py
- [ ] mlx_lm/tuner/utils.py
- [ ] mlx_lm/utils.py
- [ ] speculative_decoding/decoder.py
- [ ] speculative_decoding/model.py
- [ ] tests/test_server.py
I ran the following command to generate the above list of checkable items:
mypy \
--explicit-package-bases \
--ignore-missing-imports \
. | cut -f 1 -d ':' | sort | uniq | sed 's|^|- [ ] |'
I need --explicit-package-base; otherwise, mypy would complain an error like the following and stop working on the rest files in the project:
❯ mypy .
mistral/convert.py: error: Duplicate module named "convert" (also at "./llama/convert.py")
mistral/convert.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
mistral/convert.py: note: Common resolutions include: a) using `--exclude` to avoid checking one of them, b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or adjusting MYPYPATH
Found 1 error in 1 file (errors prevented further checking)
I need --ignore-missing-imports because even if I pip-install mlx and both mlx/ and mlx/nn/ are in conda's site directory, mypy still complains that it couldn't find type informaiton of these packages.
@awni May I take on this issue ??
How many of these are done ?
Sure! Just FYI mlx_lm has moved to a new repo https://github.com/ml-explore/mlx-lm
I don't know how many are done.. not too many It hink.
Sure! Just FYI
mlx_lmhas moved to a new repo https://github.com/ml-explore/mlx-lmI don't know how many are done.. not too many It hink.
Okay, I will start working on this. Can you please assign it to me ??
@awni I started a pull request for OpenELM models at https://github.com/ml-explore/mlx-lm/pull/61 . Can you please review it ?? I will start for the rest of the models if that looks fine.
Updated list :
- [x] mlx_lm/models/gpt2.py
- [x] mlx_lm/models/gpt_bigcode.py
- [x] mlx_lm/models/internlm2.py
- [x] mlx_lm/models/llama.py
- [x] mlx_lm/models/minicpm.py
- [x] mlx_lm/models/qwen2.py
- [x] gguf_llm/generate.py
- [x] gguf_llm/models.py
- [x] llama/convert.py
- [x] mistral/convert.py
- [x] mistral/convert.py
- [x] mixtral/convert.py
- [x] mixtral/mixtral.py
- [x] mlx_lm/lora.py
- [x] mlx_lm/merge.py
- [x] mlx_lm/server.py
- [x] mlx_lm/tuner/trainer.py
- [x] mlx_lm/tuner/utils.py
- [x] mlx_lm/utils.py
- [x] speculative_decoding/decoder.py
- [x] speculative_decoding/model.py
- [x] tests/test_server.py
gguf_llm/generate.py
gguf_llm/models.py
llama/convert.py
mistral/convert.py
mistral/convert.py
mixtral/convert.py
mixtral/mixtral.py
speculative_decoding/decoder.py
speculative_decoding/model.py
tests/test_server.py
@awni where are the following files present in the mlx-lm repo ?? I didn't find any of them
Some of those files are still in mlx-examples. The files in tests/ should be in mlx-lm now.
@awni can you please review my PR https://github.com/ml-explore/mlx-lm/pull/61. It's almost done and needs your review to proceed and merge
@awni all files done. Need your review to proceed