How ml-explore/mlx-swift-lm works
MLX Swift LM is a Swift library for loading and running LLMs and vision-language models on MLX, with related embedding, reranking, fine-tuning, guided-generation, and Foundation Models integrations. The principal workflow configures a model, loads its weights and tokenizer into a container, then generates conversational responses. README capabilities inform branches whose implementation wiring was not sampled; those branches are shown at API level rather than with inferred internal call chains.
Main entry points: ModelContainer.swift Model container · Load.swift Model loading · LLMModelFactory.swift LLM registry · GenerationComponents.swift Generation runtime
Components 18
Model runtime
- Model configuration
Libraries/MLXLMCommon/ModelConfiguration.swift - LLM registry
Libraries/MLXLLM/LLMModelFactory.swift - Model loading
Libraries/MLXLMCommon/Load.swift - Downloader integration
Libraries/MLXLMCommon/Downloader.swift - Tokenizer integration
Libraries/MLXLMCommon/TokenizerLoader.swift - Model container
Libraries/MLXLMCommon/ModelContainer.swift - LLM architectures
Libraries/MLXLLM/Models - Chat session
Libraries/MLXLMCommon/ChatSession.swift - Generation runtime
Libraries/MLXLMCommon/GenerationComponents.swift
User-facing integrations
- Constrained generation
Libraries/MLXGuidedGeneration/GuidedGenerationLoop.swift - Foundation Models bridge
Libraries/MLXFoundationModels/MLXLanguageModel.swift - Tool-call routing
Libraries/MLXLMCommon/Tool/ToolCallProcessor.swift
Specialized models
- Vision architectures
Libraries/MLXVLM/Models - Embedding models
Libraries/MLXEmbedders/EmbeddingModel.swift - Reranking
Libraries/MLXEmbedders/Reranker.swift - LoRA and training
Libraries/MLXLLM/LoraTrain.swift
Other components
- Application developer
- Hugging Face services
Connections 22
- Application developer → Model configuration: selects
- Application developer → LLM registry: loads model
- LLM registry → Model configuration: uses
- LLM registry → Model loading: creates model
- Model loading → Downloader integration: loads weights
- Model loading → Tokenizer integration: loads tokenizer
- Model loading → Model container: builds
- Model container → LLM architectures: hosts
- Model container → Vision architectures: hosts
- Application developer → Chat session: starts conversation
- Chat session → Model container: generates with
- Model container → Generation runtime: runs inference
- Application developer → Constrained generation: constrains output
- Constrained generation → Generation runtime: constrains
- Application developer → Foundation Models bridge: uses bridge
- Foundation Models bridge → Model container: adapts model
- Generation runtime → Tool-call routing: routes tool output
- Application developer → Embedding models: creates embeddings
- Application developer → Reranking: reranks
- Application developer → LoRA and training: fine-tunes
- Hugging Face services → Downloader integration: provides weights
- Hugging Face services → Tokenizer integration: provides tokenizer