Elffuss BraidHub

kikocis/mlx-vlm public

main · 2.5 KiBRenderedRawPermalink
1# Contributing to MLX VLM
2
3Below are some tips to port Vision LLMs available on Hugging Face to MLX.
4
5Next, from this directory, do an editable install:
6
7```shell
8pip install -e .
9```
10
11Then check if the model has weights in the
12[safetensors](https://huggingface.co/docs/safetensors/index) format. If not
13[follow instructions](https://huggingface.co/spaces/safetensors/convert) to
14convert it.
15
16After that, add the model file to the
17[`mlx_vlm/models`](https://github.com/Blaizzy/mlx-vlm/tree/main/src/models)
18directory. You can see other examples there. We recommend starting from a model
19that is similar to the model you are porting.
20
21Make sure the name of the new model file is the same as the `model_type` in the
22`config.json`, for example
23[llava](https://huggingface.co/llava-hf/llava-1.5-7b-hf/blob/main/config.json#L7).
24
25To determine the model layer names, we suggest either:
26
27- Refer to the Transformers implementation if you are familiar with the
28 codebase.
29- Load the model weights and check the weight names which will tell you about
30 the model structure.
31- Look at the names of the weights by inspecting `model.safetensors.index.json`
32 in the Hugging Face repo.
33
34Additionally, add a test for the new modle type to the [model
35tests](https://github.com/Blaizzy/mlx-vlm/tree/main/src/tests/test_models.py).
36
37From the `src/` directory, you can run the tests with:
38
39```shell
40python -m unittest discover tests/
41```
42
43## Pull Requests
44
451. Fork and submit pull requests to the repo.
462. If you've added code that should be tested, add tests.
473. Every PR should have passing tests and at least one review.
484. For code formatting install `pre-commit` using something like `pip install pre-commit` and run `pre-commit install`.
49 This should install hooks for running `black` and `clang-format` to ensure
50 consistent style for C++ and python code.
51
52 You can also run the formatters manually as follows on individual files:
53
54 ```bash
55 clang-format -i file.cpp
56 ```
57
58 ```bash
59 black file.py
60 ```
61
62 or,
63
64 ```bash
65 # single file
66 pre-commit run --files file1.py
67
68 # specific files
69 pre-commit run --files file1.py file2.py
70 ```
71
72 or run `pre-commit run --all-files` to check all files in the repo.
73
74## Issues
75
76We use GitHub issues to track public bugs. Please ensure your description is
77clear and has sufficient instructions to be able to reproduce the issue.
78
79## License
80
81By contributing to mlx-examples, you agree that your contributions will be licensed
82under the LICENSE file in the root directory of this source tree.