{"id":24760930,"url":"https://github.com/ziozzang/mac_mlx_phi-2_server","last_synced_at":"2025-10-11T08:30:33.542Z","repository":{"id":212624296,"uuid":"731933855","full_name":"ziozzang/Mac_mlx_phi-2_server","owner":"ziozzang","description":"Test server code for Phi-2 model. support OpenAI API spec","archived":false,"fork":false,"pushed_at":"2023-12-15T08:43:56.000Z","size":13,"stargazers_count":18,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-04T11:46:56.891Z","etag":null,"topics":["apple","inference","llm","macos","mlx","openai-api","osx","phi-2","python","server"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ziozzang.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}},"created_at":"2023-12-15T08:23:57.000Z","updated_at":"2025-03-22T20:28:05.000Z","dependencies_parsed_at":"2023-12-15T09:46:41.434Z","dependency_job_id":null,"html_url":"https://github.com/ziozzang/Mac_mlx_phi-2_server","commit_stats":null,"previous_names":["ziozzang/mac_mlx_phi-2_server"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ziozzang/Mac_mlx_phi-2_server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziozzang%2FMac_mlx_phi-2_server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziozzang%2FMac_mlx_phi-2_server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziozzang%2FMac_mlx_phi-2_server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziozzang%2FMac_mlx_phi-2_server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ziozzang","download_url":"https://codeload.github.com/ziozzang/Mac_mlx_phi-2_server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ziozzang%2FMac_mlx_phi-2_server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006611,"owners_count":26084148,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["apple","inference","llm","macos","mlx","openai-api","osx","phi-2","python","server"],"created_at":"2025-01-28T18:20:07.390Z","updated_at":"2025-10-11T08:30:33.239Z","avatar_url":"https://github.com/ziozzang.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mac_mlx_phi-2_server\n\n# Disclaimer\n- WARNING: this code is just for Fun, toy test code!\n\n1. There's no acclerated way to run phi-2 model on Mac except using MLX. pytorch using MPS is slow to run/play. but MLX is fast enough to.\n2. llama.cpp is not yet support to run phi-2. =(\n3. so, this is some toy code to run. =)\n\nOriginal inference codes are came from https://github.com/ml-explore/mlx-examples/tree/main/phi2\n\n# Feature\nTest server code for Phi-2 model. support OpenAI API spec. using MacOSX system.\n\nyou can use same api with OpenAI API spec.\n\n# How to use?\n\n```\n# Install requirements\npip install -r requirements.txt\n\n# Convert Model to MLX format\npython convert.py\n\n# Run Server.\npython phi2-server.py\n\n# Use anyway.\ncurl http://localhost:5000/v1/chat/completions \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n     \"model\": \"gpt-3.5-turbo\",\n     \"messages\": [{\"role\": \"user\", \"content\": \"answer why sky is so blue?\"}],\n     \"temperature\": 0.5\n   }'\n```\n\n# Issue\n- Need to change prompt to get better inference. this is just test. any pull-requests are welcome!\n\n----\n\n# Phi-2\n\nPhi-2 is a 2.7B parameter language model released by Microsoft with\nperformance that rivals much larger models.[^1] It was trained on a mixture of\nGPT-4 outputs and clean web text.\n\nPhi-2 efficiently runs on Apple silicon devices with 8GB of memory in 16-bit\nprecision.\n\n## Setup \n\nDownload and convert the model:\n\n```sh \npython convert.py\n```\n\nThis will make the `weights.npz` file which MLX can read.\n\n## Generate \n\nTo generate text with the default prompt:\n\n```sh\npython phi2.py\n```\n\nShould give the output:\n\n```\nAnswer: Mathematics is like a lighthouse that guides us through the darkness of\nuncertainty. Just as a lighthouse emits a steady beam of light, mathematics\nprovides us with a clear path to navigate through complex problems. It\nilluminates our understanding and helps us make sense of the world around us.\n\nExercise 2:\nCompare and contrast the role of logic in mathematics and the role of a compass\nin navigation.\n\nAnswer: Logic in mathematics is like a compass in navigation. It helps\n```\n\nTo use your own prompt:\n\n```sh\npython phi2.py --prompt \u003cyour prompt here\u003e --max_tokens \u003cmax_tokens_to_generate\u003e\n```\n\nTo see a list of options run:\n\n```sh\npython phi2.py --help\n```\n\n[^1]: For more details on the model see the [blog post](\nhttps://www.microsoft.com/en-us/research/blog/phi-2-the-surprising-power-of-small-language-models/)\nand the [Hugging Face repo](https://huggingface.co/microsoft/phi-2)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziozzang%2Fmac_mlx_phi-2_server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fziozzang%2Fmac_mlx_phi-2_server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fziozzang%2Fmac_mlx_phi-2_server/lists"}