| 1 | # Contributing to MLX VLM |
| 2 | |
| 3 | Below are some tips to port Vision LLMs available on Hugging Face to MLX. |
| 4 | |
| 5 | Next, from this directory, do an editable install: |
| 6 | |
| 7 | ```shell |
| 8 | pip install -e . |
| 9 | ``` |
| 10 | |
| 11 | Then 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 |
| 14 | convert it. |
| 15 | |
| 16 | After that, add the model file to the |
| 17 | [`mlx_vlm/models`](https://github.com/Blaizzy/mlx-vlm/tree/main/src/models) |
| 18 | directory. You can see other examples there. We recommend starting from a model |
| 19 | that is similar to the model you are porting. |
| 20 | |
| 21 | Make 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 | |
| 25 | To 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 | |
| 34 | Additionally, add a test for the new modle type to the [model |
| 35 | tests](https://github.com/Blaizzy/mlx-vlm/tree/main/src/tests/test_models.py). |
| 36 | |
| 37 | From the `src/` directory, you can run the tests with: |
| 38 | |
| 39 | ```shell |
| 40 | python -m unittest discover tests/ |
| 41 | ``` |
| 42 | |
| 43 | ## Pull Requests |
| 44 | |
| 45 | 1. Fork and submit pull requests to the repo. |
| 46 | 2. If you've added code that should be tested, add tests. |
| 47 | 3. Every PR should have passing tests and at least one review. |
| 48 | 4. 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 | |
| 76 | We use GitHub issues to track public bugs. Please ensure your description is |
| 77 | clear and has sufficient instructions to be able to reproduce the issue. |
| 78 | |
| 79 | ## License |
| 80 | |
| 81 | By contributing to mlx-examples, you agree that your contributions will be licensed |
| 82 | under the LICENSE file in the root directory of this source tree. |