{"id":18608949,"url":"https://github.com/riccardomusmeci/mlx-llm","last_synced_at":"2025-04-04T16:14:26.770Z","repository":{"id":212862659,"uuid":"728758093","full_name":"riccardomusmeci/mlx-llm","owner":"riccardomusmeci","description":"Large Language Models (LLMs) applications and tools running on Apple Silicon in real-time with Apple MLX.","archived":false,"fork":false,"pushed_at":"2024-08-24T12:55:58.000Z","size":1938,"stargazers_count":319,"open_issues_count":0,"forks_count":28,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-10-18T23:17:30.717Z","etag":null,"topics":["llama","llm","mistral","mlx","phi","transformers"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/riccardomusmeci.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-07T16:19:47.000Z","updated_at":"2024-10-17T11:57:28.000Z","dependencies_parsed_at":"2023-12-19T08:41:38.570Z","dependency_job_id":"7b7bfa63-49f9-4555-8f06-6d98807ec55a","html_url":"https://github.com/riccardomusmeci/mlx-llm","commit_stats":{"total_commits":170,"total_committers":3,"mean_commits":"56.666666666666664","dds":0.01764705882352946,"last_synced_commit":"e6a2c98c77c893b532f2e56aba9b37bc6299cca8"},"previous_names":["riccardomusmeci/mlx-llm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riccardomusmeci%2Fmlx-llm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riccardomusmeci%2Fmlx-llm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riccardomusmeci%2Fmlx-llm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/riccardomusmeci%2Fmlx-llm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/riccardomusmeci","download_url":"https://codeload.github.com/riccardomusmeci/mlx-llm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247208145,"owners_count":20901570,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["llama","llm","mistral","mlx","phi","transformers"],"created_at":"2024-11-07T03:04:46.777Z","updated_at":"2025-04-04T16:14:26.751Z","avatar_url":"https://github.com/riccardomusmeci.png","language":"Python","funding_links":[],"categories":["HarmonyOS","LLM \u0026 Inference","Libraries and Tools","Building","Python"],"sub_categories":["Windows Manager","2024","LLM Models"],"readme":"# mlx-llm\nLarge Language Models (LLMs) applications and tools running on Apple Silicon in real-time with [Apple MLX](https://github.com/ml-explore/mlx).\n\n![Alt Text](static/mlx-llm-demo.gif)\n\nGo to the entire [Youtube Video](https://www.youtube.com/watch?v=vB7tk6W6VIw).\n\n## **How to install 🔨**\n```\npip install mlx-llm\n```\n\n## **Models 🧠**\n\nCurrently, out-of-the-box supported models are:\n\n| Family        |  Models |\n|---------------------|----------------|\n| LLaMA 2                  |     llama_2_7b_chat_hf, llama_2_7b_hf            |\n| LLaMA 3          |  deepseek_r1_distill_llama_8b, llama_3_8b, llama_3_8b_instruct, hermes_2_pro_llama_3_8b, llama_3_2_1b_instruct, llama_3_2_3b_instruct             |\n| Phi3 |   phi_3_mini_4k_instruct, phi_3_mini_128k_instruct, phi_3.5_mini_instruct        |\n| Mistral |  mistral_7b_instruct_v0.2, openhermes_2.5_mistral_7b, starling_lm_7b_beta          |\n| TinyLLaMA |     tiny_llama_1.1B_chat_v1.0       |\n| Gemma |  gemma_1.1_2b_it, gemma_1.1_7b_it, gemma_2_2b_it, gemma_2_9b_it                    |\n| OpenELM |  openelm_270M_instruct, openelm_450M_instruct, openelm_1.1B_instruct, openelm_3B_instruct |\n| SmolLM2 |  smollm2_1.7B_instruct, smollm2_360M_instruct, smollm2_135M_instruct |\n\nTo create a model with pre-trained weights from HuggingFace:\n\n```python\nfrom mlx_llm.model import create_model\n\n# loading weights from HuggingFace\nmodel = create_model(\"deepseek_r1_distill_llama_8b\")\n```\n\nYou can also load a new version of pre-trained weights for a specific model directly from HuggingFace:\n- set `weights` by adding `hf://` before the HuggingFace repository \n- if necessary, specify custom model configs (rope_theta, rope_traditional, vocab_size, norm_eps)\n\nHere's an example of how to to it:\n```python\nfrom mlx_llm.model import create_model\n\n# an example of loading new weights from HuggingFace\nmodel = create_model(\n    model_name=\"openelm_1.1B_instruct\", # it's the base model\n    weights=\"hf://apple/OpenELM-1.1B\", # new weights from HuggingFace\n)\n\n# an example of loading new weights from HuggingFace with custom model configs\nmodel = create_model(\n    model_name=\"llama_3_8b_instruct\", # it's the base model\n    weights=\"hf://gradientai/Llama-3-8B-Instruct-262k\", # new weights from HuggingFace\n    model_config={\n        \"rope_theta\": 207112184.0\n    }\n)\n```\n\n### **Quantization 📉**\n\nTo quantize a model and save its weights just use:\n\n```python\nfrom mlx_llm.model import create_model, quantize, get_weights\nfrom mlx_llm.utils.weights import save_weights\n\n# create the model from original weights\nmodel = create_model(\"llama_3_8b_instruct\")\n# quantize the model\nmodel = quantize(model, group_size=64, bits=4)\n# getting weights dict (similar to state_dict in PyTorch)\nweights = get_weights(model)\n# save the model\nsave_weights(weights, \"llama_3_8b_instruct-4bit.safetensors\")\n```\n\n### **Model Embeddings ✴️**\nModels in `mlx-llm` are able to extract embeddings from a given text.\n\n```python\nimport mlx.core as mx\nfrom mlx_llm.model import create_model, create_tokenizer\n\nmodel = create_model(\"llama_3_8b_instruct\")\ntokenizer = create_tokenizer('llama_3_8b_instruct')\ntext = [\"I like to play basketball\", \"I like to play tennis\"]\ntokens = tokenizer(text)\nx = mx.array(tokens[\"input_ids\"])\nembeds, _ = model.embed(x, norm=True)\n```\n\n### **Chat with LLM 📱**\n`mlx-llm` comes with tools to easily run your LLM chat on Apple Silicon.\n\nTo chat with an LLM provide:\n- a system prompt --\u003e to set the overall tone of the LLM\n- optional previous interactions to set the mood of the conversation\n\n```python\nfrom mlx_llm.chat import ChatSetup, LLMChat\n\nmodel_name = \"tiny_llama_1.1B_chat_v1.0\"\n\nchat = LLMChat(\n    model_name=model_name,\n    chat_setup=ChatSetup(\n        system=\"You are Michael Scott from The Office. Your goal is to answer like him, so be funny and inappropriate, but be brief.\",\n        history=[\n            {\"question\": \"What is your name?\", \"answer\": \"Michael Scott\"},\n            {\"question\": \"What is your favorite episode of The Office?\", \"answer\": \"The Dinner Party\"},\n        ],\n    ),\n    quantized=False, # if you want it faster use the quantization params (e.g., group_size=64, bits=4)\n)\n\nchat.start()\n```\n\n\u003e [!WARNING]\n\u003e OpenELM chat-mode is broken. I am working on fixing it.\n\n## 📧 Contact\n\nIf you have any questions, please email `riccardomusmeci92@gmail.com`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friccardomusmeci%2Fmlx-llm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Friccardomusmeci%2Fmlx-llm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Friccardomusmeci%2Fmlx-llm/lists"}