### Example: Export LORA Adapter Source: https://github.com/guinmoon/llmfarm_core.swift/blob/main/Sources/llmfarm_core_cpp/finetune/README_export.md Demonstrates how to apply a single LORA adapter to a base model and save the exported model. Ensure the paths for the base model, output, and LORA adapter are correct. ```bash ./bin/export-lora \ -m open-llama-3b-v2-q8_0.gguf \ -o open-llama-3b-v2-q8_0-english2tokipona-chat.gguf \ -l lora-open-llama-3b-v2-q8_0-english2tokipona-chat-LATEST.bin ``` -------------------------------- ### Initialize and Run LLM with AI Class Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt Demonstrates initializing the `AI` class, configuring model parameters including prompt format and Metal acceleration, loading the model synchronously, and running a conversation with streaming callbacks. Use this for direct interaction with LLMs. ```swift import llmfarm_core // Initialize AI with model path and chat name let ai = AI(_modelPath: "/path/to/model.gguf", _chatName: "my_chat") // Configure model parameters var params: ModelAndContextParams = .default params.context = 2048 params.n_threads = 8 params.use_metal = true // Enable Metal acceleration on Apple Silicon // Set custom prompt format params.promptFormat = .Custom params.custom_prompt_format = """ SYSTEM: You are a helpful assistant. USER: {prompt} ASSISTANT: """ // Initialize the model with inference type ai.initModel(ModelInference.LLama_gguf, contextParams: params) // Load model synchronously do { try ai.loadModel_sync() print("Model loaded successfully") } catch { print("Failed to load model: \(error)") } // Run conversation with streaming callback ai.conversation( "What is the capital of France?", { token, time in // Token callback - called for each generated token print(token, terminator: "") }, { info, value in // Info callback - receives metadata like token counts print("Info: \(info) = \(value)") }, { result in // Completion callback print("\nGeneration complete: \(result)") }, system_prompt: "You are a geography expert.", img_path: nil // Optional image path for multimodal models ) // Stop generation early ai.flagExit = true ``` -------------------------------- ### Initialize and Run LLM Inference in Swift Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt Demonstrates the complete lifecycle of loading a GGUF model, configuring inference parameters, and generating text with a token callback. ```swift import Foundation import llmfarm_core // Configuration let modelPath = "/Users/user/models/llama-7b-chat.Q4_K_M.gguf" let maxOutputLength = 256 var totalOutput = 0 // Token callback with length limit func tokenCallback(_ token: String, _ time: Double) -> Bool { print(token, terminator: "") fflush(stdout) totalOutput += token.count return totalOutput > maxOutputLength } // Initialize AI let ai = AI(_modelPath: modelPath, _chatName: "demo_chat") // Configure parameters var params = ModelAndContextParams.default params.context = 2048 params.n_threads = Int32(ProcessInfo.processInfo.processorCount) params.use_metal = true params.n_predict = 512 // ChatML prompt format params.promptFormat = .Custom params.custom_prompt_format = """ <|im_start|>system You are a helpful, respectful and honest assistant.<|im_end|> <|im_start|>user {prompt}<|im_end|> <|im_start|>assistant """ // Initialize model ai.initModel(ModelInference.LLama_gguf, contextParams: params) guard ai.model != nil else { print("Failed to initialize model") exit(1) } // Configure sampling for balanced creativity ai.model?.sampleParams.temp = 0.7 ai.model?.sampleParams.top_k = 40 ai.model?.sampleParams.top_p = 0.9 ai.model?.sampleParams.repeat_penalty = 1.1 // Load model synchronously do { try ai.loadModel_sync() print("Model loaded successfully\n") } catch { print("Failed to load model: \(error)") exit(1) } // Generate response let prompt = "Write a haiku about programming" print("Prompt: \(prompt)\n") print("Response: ", terminator: "") do { let output = try ai.model?.Predict( prompt, tokenCallback, system_prompt: nil, img_path: nil, infoCallback: { key, value in // Silent info callback } ) print("\n\nGeneration complete!") } catch { print("\nError during generation: \(error)") } ``` -------------------------------- ### Configure models from dictionaries Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt Parse model and sampling parameters from a dictionary to initialize AI instances. ```swift import llmfarm_core // Configuration dictionary (e.g., from JSON) let config: [String: AnyObject] = [ "model": "llama-7b.gguf" as AnyObject, "context": 4096 as AnyObject, "numberOfThreads": 8 as AnyObject, "n_predict": 512 as AnyObject, "use_metal": true as AnyObject, "mmap": true as AnyObject, "mlock": false as AnyObject, "flash_attn": false as AnyObject, "add_bos_token": true as AnyObject, "add_eos_token": false as AnyObject, "parse_special_tokens": true as AnyObject, "save_load_state": true as AnyObject, "reverse_prompt": "USER:,Human:" as AnyObject, "skip_tokens": "<|im_start|>,<|im_end|>" as AnyObject, "prompt_format": "[INST] {prompt} [/INST]" as AnyObject, // Sampling parameters "temp": 0.7 as AnyObject, "top_k": 40 as AnyObject, "top_p": 0.95 as AnyObject, "tfs_z": 1.0 as AnyObject, "typical_p": 1.0 as AnyObject, "repeat_penalty": 1.1 as AnyObject, "repeat_last_n": 64 as AnyObject, "frequence_penalty": 0.0 as AnyObject, "presence_penalty": 0.0 as AnyObject, "mirostat": 2 as AnyObject, "mirostat_tau": 5.0 as AnyObject, "mirostat_eta": 0.1 as AnyObject, "n_batch": 512 as AnyObject, // LoRA adapters "lora_adapters": [ ["adapter": "lora-shakespeare.bin", "scale": 1.0], ["adapter": "lora-poetry.bin", "scale": 0.5] ] as AnyObject, // Multimodal "clip_model": "clip-vit-large.gguf" as AnyObject, "use_clip_metal": true as AnyObject, // Model inference type "model_inference": "llama" as AnyObject ] // Parse context parameters let contextParams = get_model_context_param_by_config(config) // Parse sampling parameters let sampleParams = get_model_sample_param_by_config(config) // Use with AI let ai = AI(_modelPath: "/models/\(config["model"]!)", _chatName: "chat") ai.initModel(contextParams.model_inference, contextParams: contextParams) ai.model?.sampleParams = sampleParams ``` -------------------------------- ### Download Training Data Source: https://github.com/guinmoon/llmfarm_core.swift/blob/main/Sources/llmfarm_core_cpp/finetune/README_finetune.md Use wget to download the Shakespeare dataset for training. ```bash # get training data wget https://raw.githubusercontent.com/brunoklein99/deep-learning-notes/master/shakespeare.txt ``` -------------------------------- ### Configure Model and Context Parameters Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt Shows how to customize `ModelAndContextParams` for detailed control over model loading and inference, including context size, threading, hardware acceleration, LoRA adapters, and multimodal settings. Adjust these for specific model requirements. ```swift import llmfarm_core // Create custom context parameters var contextParams = ModelAndContextParams( context: 4096, // Context window size parts: -1, // Model parts (-1 for auto) seed: 12345, // RNG seed (0xFFFFFFFF for random) numberOfThreads: 0, // 0 = auto-detect CPU threads f16Kv: true, // Use FP16 for KV cache logitsAll: false, // Compute all logits vocabOnly: false, // Only load vocabulary useMlock: false, // Lock model in RAM useMMap: true, // Use memory-mapped files embedding: false // Embedding mode ) // Hardware acceleration contextParams.use_metal = true // Enable Metal GPU contextParams.use_clip_metal = true // Metal for CLIP (multimodal) contextParams.flash_attn = false // Flash attention // Prediction settings contextParams.n_predict = 512 // Max tokens to generate (0 = unlimited) // LoRA adapters - array of (path, scale) tuples contextParams.lora_adapters = [ ("/path/to/lora-adapter.bin", 1.0), ("/path/to/another-lora.bin", 0.5) ] // Multimodal settings contextParams.clip_model = "/path/to/clip-model.gguf" // Token handling contextParams.add_bos_token = true contextParams.add_eos_token = false contextParams.parse_special_tokens = true // Reverse prompts (stop sequences) contextParams.reverse_prompt = ["USER:", "Human:"] // State persistence contextParams.save_load_state = true contextParams.state_dump_path = "/path/to/state.bin" // Custom prompt format with system prompt contextParams.promptFormat = .Custom contextParams.custom_prompt_format = "[system](You are helpful){prompt}" contextParams.system_prompt = "You are a helpful AI assistant." ``` -------------------------------- ### Export LORA Adapters Command Line Options Source: https://github.com/guinmoon/llmfarm_core.swift/blob/main/Sources/llmfarm_core_cpp/finetune/README_export.md Lists the available command-line options for the export-lora script. Use these to specify the base model, output path, LORA adapters, and computation threads. ```bash usage: export-lora [options] options: -h, --help show this help message and exit -m FNAME, --model-base FNAME model path from which to load base model (default '') -o FNAME, --model-out FNAME path to save exported model (default '') -l FNAME, --lora FNAME apply LoRA adapter -s FNAME S, --lora-scaled FNAME S apply LoRA adapter with user defined scaling S -t N, --threads N number of threads to use during computation (default: 4) ``` -------------------------------- ### Load models asynchronously with Swift Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt Use progress and completion callbacks to handle background model loading for responsive UI updates. ```swift import llmfarm_core let ai = AI(_modelPath: "/path/to/large-model.gguf", _chatName: "chat") ai.initModel(ModelInference.LLama_gguf, contextParams: .default) // Set progress callback ai.model?.modelLoadProgressCallback = { progress in let percentage = Int(progress * 100) print("Loading: \(percentage)%") // Return false to continue, true to cancel return false } // Set completion callback ai.model?.modelLoadCompleteCallback = { status in if status == "[Done]" { print("Model loaded successfully!") // Start using the model } else { print("Load failed: \(status)") } } // Start async loading ai.loadModel() // Model loads in background, callbacks fire on main thread ``` -------------------------------- ### Finetune LORA Adapter Source: https://github.com/guinmoon/llmfarm_core.swift/blob/main/Sources/llmfarm_core_cpp/finetune/README_finetune.md Finetune a LORA adapter for a Llama-based model using the finetune script. Ensure the base model and checkpoint files are correctly specified. Output files are saved periodically and the latest version is marked. ```bash # finetune LORA adapter ./bin/finetune \ --model-base open-llama-3b-v2-q8_0.gguf \ --checkpoint-in chk-lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.gguf \ --checkpoint-out chk-lora-open-llama-3b-v2-q8_0-shakespeare-ITERATION.gguf \ --lora-out lora-open-llama-3b-v2-q8_0-shakespeare-ITERATION.bin \ --train-data "shakespeare.txt" \ --save-every 10 \ --threads 6 --adam-iter 30 --batch 4 --ctx 64 \ --use-checkpointing ``` -------------------------------- ### Clone the repository Source: https://github.com/guinmoon/llmfarm_core.swift/blob/main/README.md Use this command to clone the LLMFarm_core repository to your local machine. ```bash git clone https://github.com/guinmoon/llmfarm_core.swift ``` -------------------------------- ### Initialize Models with ModelInference Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt Select the appropriate model architecture using the ModelInference enum. Multimodal models require additional context parameters for CLIP model paths. ```swift import llmfarm_core // Available inference types let llamaGGUF = ModelInference.LLama_gguf // LLaMA models in GGUF format (recommended) let llamaBin = ModelInference.LLama_bin // Legacy LLaMA GGJTv3 format let llamaMM = ModelInference.LLama_mm // Multimodal LLaMA (LLaVA) let gptNeox = ModelInference.GPTNeox // GPT-NeoX models let gptNeoxGGUF = ModelInference.GPTNeox_gguf // GPT-NeoX in GGUF let gpt2 = ModelInference.GPT2 // GPT-2 models let replit = ModelInference.Replit // Replit code models let starcoder = ModelInference.Starcoder // Starcoder models let starcoderGGUF = ModelInference.Starcoder_gguf let rwkv = ModelInference.RWKV // RWKV models // Initialize with specific inference type let ai = AI(_modelPath: "/path/to/llama-7b.gguf", _chatName: "chat") ai.initModel(ModelInference.LLama_gguf, contextParams: .default) // Multimodal model with CLIP var mmParams = ModelAndContextParams.default mmParams.clip_model = "/path/to/clip-model.gguf" ai.initModel(ModelInference.LLama_mm, contextParams: mmParams) ``` -------------------------------- ### Load and Mix Multiple LORA Adapters Source: https://github.com/guinmoon/llmfarm_core.swift/blob/main/Sources/llmfarm_core_cpp/finetune/README_finetune.md Load and mix multiple LORA adapters with the base model for prediction. Each adapter is specified with a separate --lora flag. ```bash ./bin/main -m open-llama-3b-v2-q8_0.gguf \ --lora lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.bin \ --lora lora-open-llama-3b-v2-q8_0-bible-LATEST.bin ``` -------------------------------- ### Load and Scale LORA Adapters Source: https://github.com/guinmoon/llmfarm_core.swift/blob/main/Sources/llmfarm_core_cpp/finetune/README_finetune.md Load LORA adapters with specified scaling factors. Use --lora-scaled to apply a percentage of an adapter's influence. Scales do not need to sum to one and can exceed 1. ```bash ./bin/main -m open-llama-3b-v2-q8_0.gguf \ --lora-scaled lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.bin 0.4 \ --lora-scaled lora-open-llama-3b-v2-q8_0-bible-LATEST.bin 0.8 \ --lora lora-open-llama-3b-v2-q8_0-yet-another-one-LATEST.bin ``` -------------------------------- ### Finetune Configuration Options Source: https://github.com/guinmoon/llmfarm_core.swift/blob/main/Sources/llmfarm_core_cpp/finetune/README_finetune.md Command line options for configuring LORA rank during finetuning. The default rank is 4. Specific ranks can be set for different tensor types, with 'norm' tensors typically requiring a rank of 1. ```bash --lora-r N LORA r: default rank. Also specifies resulting scaling together with lora-alpha. (default 4) --rank-att-norm N LORA rank for attention norm tensor (default 1) --rank-ffn-norm N LORA rank for feed-forward norm tensor (default 1) --rank-out-norm N LORA rank for output norm tensor (default 1) --rank-tok-embd N LORA rank for token embeddings tensor (default 4) --rank-out N LORA rank for output tensor (default 4) --rank-wq N LORA rank for wq tensor (default 4) --rank-wk N LORA rank for wk tensor (default 4) --rank-wv N LORA rank for wv tensor (default 4) --rank-wo N LORA rank for wo tensor (default 4) --rank-w1 N LORA rank for w1 tensor (default 4) --rank-w2 N LORA rank for w2 tensor (default 4) --rank-w3 N LORA rank for w3 tensor (default 4) ``` -------------------------------- ### Fine-tune models with LoRA Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt Configure and execute LoRA fine-tuning sessions with support for custom training parameters and hardware acceleration. ```swift import llmfarm_core // Initialize fine-tuning session let fineTune = FineTune( "/path/to/base-model.gguf", // Base model path "/path/to/output-lora.bin", // Output LoRA adapter path "/path/to/training-data.txt", // Training data file threads: 8, // CPU threads adam_iter: 30, // Adam optimizer iterations batch: 4, // Batch size ctx: 64, // Context size for training use_checkpointing: true, // Enable gradient checkpointing use_metal: true, // Use Metal acceleration export_model: "/path/to/merged.gguf" // Optional: export merged model ) // Set export scale for LoRA merging fineTune.export_scale = 1.0 // Progress callback do { try fineTune.finetune { log in print("Training: \(log)") } } catch { print("Fine-tuning failed: \(error)") } // Cancel training fineTune.cancel = true ``` -------------------------------- ### Configure Model Sampling Parameters Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt Use ModelSampleParams to adjust generation behavior like temperature, top-k/top-p, and penalties. Parameters can be set during initialization or modified directly on the model instance. ```swift import llmfarm_core // Create custom sampling parameters var sampleParams = ModelSampleParams( n_batch: 512, // Batch size for evaluation temp: 0.7, // Temperature (0 = greedy) top_k: 40, // Top-K sampling (0 = disabled) top_p: 0.95, // Top-P (nucleus) sampling min_p: 0.0, // Minimum probability threshold tfs_z: 1.0, // Tail Free Sampling (1.0 = disabled) typical_p: 1.0, // Locally Typical Sampling (1.0 = disabled) repeat_penalty: 1.1, // Repetition penalty repeat_last_n: 64, // Context for repetition penalty frequence_penalty: 0.0, // Frequency penalty presence_penalty: 0.0, // Presence penalty mirostat: 0, // Mirostat mode (0=off, 1=v1, 2=v2) mirostat_tau: 5.0, // Mirostat target entropy mirostat_eta: 0.1, // Mirostat learning rate penalize_nl: true // Penalize newlines ) // Apply to model after loading ai.model?.sampleParams = sampleParams // Or modify individual parameters ai.model?.sampleParams.temp = 0.8 ai.model?.sampleParams.mirostat = 2 // Enable Mirostat v2 ai.model?.sampleParams.mirostat_tau = 5.0 ai.model?.sampleParams.mirostat_eta = 0.1 // Greedy sampling (deterministic) ai.model?.sampleParams.temp = 0 // Creative sampling ai.model?.sampleParams.temp = 1.2 ai.model?.sampleParams.top_k = 100 ai.model?.sampleParams.top_p = 0.9 ``` -------------------------------- ### Predict with LORA Adapter Source: https://github.com/guinmoon/llmfarm_core.swift/blob/main/Sources/llmfarm_core_cpp/finetune/README_finetune.md Use the finetuned LORA adapter with the base model for prediction. The LORA adapter is specified using the --lora flag. ```bash # predict ./bin/main -m open-llama-3b-v2-q8_0.gguf --lora lora-open-llama-3b-v2-q8_0-shakespeare-LATEST.bin ``` -------------------------------- ### Add dependency via Swift Package Manager Source: https://github.com/guinmoon/llmfarm_core.swift/blob/main/README.md Include this dependency in your Package.swift file to integrate the library into your project. ```swift dependencies: [ .package(url: "https://github.com/guinmoon/llmfarm_core.swift") ] ``` -------------------------------- ### ModelSampleParams - Sampling Configuration Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt The ModelSampleParams struct controls text generation sampling behavior including temperature, top-k/top-p filtering, repetition penalties, and Mirostat sampling methods. ```APIDOC ## ModelSampleParams - Sampling Configuration The `ModelSampleParams` struct controls text generation sampling behavior including temperature, top-k/top-p filtering, repetition penalties, and Mirostat sampling methods. ### Parameters - **n_batch** (Int) - Batch size for evaluation - **temp** (Double) - Temperature (0 = greedy) - **top_k** (Int) - Top-K sampling (0 = disabled) - **top_p** (Double) - Top-P (nucleus) sampling - **min_p** (Double) - Minimum probability threshold - **tfs_z** (Double) - Tail Free Sampling (1.0 = disabled) - **typical_p** (Double) - Locally Typical Sampling (1.0 = disabled) - **repeat_penalty** (Double) - Repetition penalty - **repeat_last_n** (Int) - Context for repetition penalty - **frequence_penalty** (Double) - Frequency penalty - **presence_penalty** (Double) - Presence penalty - **mirostat** (Int) - Mirostat mode (0=off, 1=v1, 2=v2) - **mirostat_tau** (Double) - Mirostat target entropy - **mirostat_eta** (Double) - Mirostat learning rate - **penalize_nl** (Bool) - Penalize newlines ### Request Example ```swift import llmfarm_core // Create custom sampling parameters var sampleParams = ModelSampleParams( n_batch: 512, temp: 0.7, top_k: 40, top_p: 0.95, min_p: 0.0, tfs_z: 1.0, typical_p: 1.0, repeat_penalty: 1.1, repeat_last_n: 64, frequence_penalty: 0.0, presence_penalty: 0.0, mirostat: 0, mirostat_tau: 5.0, mirostat_eta: 0.1, penalize_nl: true ) // Apply to model after loading ai.model?.sampleParams = sampleParams // Or modify individual parameters ai.model?.sampleParams.temp = 0.8 ai.model?.sampleParams.mirostat = 2 // Enable Mirostat v2 ai.model?.sampleParams.mirostat_tau = 5.0 ai.model?.sampleParams.mirostat_eta = 0.1 // Greedy sampling (deterministic) ai.model?.sampleParams.temp = 0 // Creative sampling ai.model?.sampleParams.temp = 1.2 ai.model?.sampleParams.top_k = 100 ai.model?.sampleParams.top_p = 0.9 ``` ``` -------------------------------- ### Execute Direct Prediction with LLMBase Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt Use the Predict method for fine-grained control over text generation, including token-by-token callbacks and metadata handling. ```swift import llmfarm_core // After model is loaded guard let model = ai.model else { print("Model not loaded") return } // Token callback returning Bool (true = stop generation) var totalTokens = 0 let maxTokens = 256 let tokenCallback: (String, Double) -> Bool = { token, generationTime in print(token, terminator: "") totalTokens += 1 return totalTokens >= maxTokens // Stop when reaching max } // Info callback for metadata let infoCallback: (String, Any) -> Void = { key, value in switch key { case "itc": print("Input token count: \(value)") case "otc": print("Output token count: \(value)") default: print("\(key): \(value)") } } // Run prediction do { let output = try model.Predict( "Explain quantum computing", tokenCallback, system_prompt: "You are a physics professor.", img_path: nil, // Image path for multimodal models infoCallback: infoCallback ) print("\n\nFull output: \(output)") } catch ModelError.inputTooLong { print("Input exceeds context window") } catch ModelError.failedToEval { print("Evaluation failed") } catch { print("Error: \(error)") } ``` -------------------------------- ### LLMBase.Predict - Direct Prediction Method Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt The Predict method on LLMBase provides direct access to text generation with fine-grained control over the generation loop, token callbacks, and multimodal inputs. ```APIDOC ## LLMBase.Predict - Direct Prediction Method The `Predict` method on `LLMBase` provides direct access to text generation with fine-grained control over the generation loop, token callbacks, and multimodal inputs. ### Method `Predict` ### Parameters - **prompt** (String) - The input prompt for text generation. - **tokenCallback** ( (String, Double) -> Bool ) - A callback function executed for each generated token. Returning `true` stops generation. - **system_prompt** (String, Optional) - An optional system prompt to guide the model's behavior. - **img_path** (String?, Optional) - An optional path to an image for multimodal models. - **infoCallback** ( (String, Any) -> Void, Optional) - A callback function for receiving metadata about the generation process (e.g., token counts). ### Request Example ```swift import llmfarm_core // After model is loaded guard let model = ai.model else { print("Model not loaded") return } // Token callback returning Bool (true = stop generation) var totalTokens = 0 let maxTokens = 256 let tokenCallback: (String, Double) -> Bool = { token, generationTime in print(token, terminator: "") totalTokens += 1 return totalTokens >= maxTokens // Stop when reaching max } // Info callback for metadata let infoCallback: (String, Any) -> Void = { key, value in switch key { case "itc": print("Input token count: \(value)") case "otc": print("Output token count: \(value)") default: print("\(key): \(value)") } } // Run prediction do { let output = try model.Predict( "Explain quantum computing", tokenCallback, system_prompt: "You are a physics professor.", img_path: nil, // Image path for multimodal models infoCallback: infoCallback ) print("\n\nFull output: \(output)") } catch ModelError.inputTooLong { print("Input exceeds context window") } catch ModelError.failedToEval { print("Evaluation failed") } catch { print("Error: \(error)") } ``` ### Response #### Success Response (200) - **output** (String) - The generated text output from the model. #### Error Handling - **ModelError.inputTooLong**: Indicates the input exceeds the model's context window. - **ModelError.failedToEval**: Indicates a failure during the model's evaluation process. - **Error**: Catches any other unexpected errors during prediction. ``` -------------------------------- ### ModelInference - Supported Model Types Source: https://context7.com/guinmoon/llmfarm_core.swift/llms.txt The ModelInference enum defines supported model architectures and formats for initialization. ```APIDOC ## ModelInference - Supported Model Types The `ModelInference` enum defines supported model architectures and formats for initialization. ### Supported Model Types - **LLama_gguf**: LLaMA models in GGUF format (recommended) - **LLama_bin**: Legacy LLaMA GGJTv3 format - **LLama_mm**: Multimodal LLaMA (LLaVA) - **GPTNeox**: GPT-NeoX models - **GPTNeox_gguf**: GPT-NeoX in GGUF - **GPT2**: GPT-2 models - **Replit**: Replit code models - **Starcoder**: Starcoder models - **Starcoder_gguf**: Starcoder in GGUF - **RWKV**: RWKV models ### Request Example ```swift import llmfarm_core // Available inference types let llamaGGUF = ModelInference.LLama_gguf let llamaBin = ModelInference.LLama_bin let llamaMM = ModelInference.LLama_mm let gptNeox = ModelInference.GPTNeox let gptNeoxGGUF = ModelInference.GPTNeox_gguf let gpt2 = ModelInference.GPT2 let replit = ModelInference.Replit let starcoder = ModelInference.Starcoder let starcoderGGUF = ModelInference.Starcoder_gguf let rwkv = ModelInference.RWKV // Initialize with specific inference type let ai = AI(_modelPath: "/path/to/llama-7b.gguf", _chatName: "chat") ai.initModel(ModelInference.LLama_gguf, contextParams: .default) // Multimodal model with CLIP var mmParams = ModelAndContextParams.default mmParams.clip_model = "/path/to/clip-model.gguf" ai.initModel(ModelInference.LLama_mm, contextParams: mmParams) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.