From 297fd7a67a1e79c77c66a77e4c85f9822842342e Mon Sep 17 00:00:00 2001 From: SB Yoon <44089734+yansigit@users.noreply.github.com> Date: Fri, 8 Aug 2025 23:20:23 -0600 Subject: [PATCH] Fix the return value in MLX loader and add named constants for magic numbers --- modules/mlx_loader.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/mlx_loader.py b/modules/mlx_loader.py index 80aa987a..5cfc3059 100644 --- a/modules/mlx_loader.py +++ b/modules/mlx_loader.py @@ -5,6 +5,10 @@ from pathlib import Path import modules.shared as shared from modules.logging_colors import logger +# Constants for MLX configuration +MLX_TOP_P_DISABLED = 0.0 # MLX expects 0.0 to disable top_p +DEFAULT_MAX_TOKENS = 512 # Default maximum tokens for generation + def is_apple_silicon(): """Check if running on Apple Silicon""" @@ -46,7 +50,7 @@ class MLXModel: instance.tokenizer = tokenizer logger.info(f"Successfully loaded MLX model: {model_name}") - return instance, instance # Return model, tokenizer tuple for compatibility + return instance # Return instance for compatibility except Exception as e: error_msg = str(e) @@ -112,7 +116,7 @@ class MLXModel: # Create the sampler sampler = make_sampler( temp=temperature, - top_p=top_p if top_p < 1.0 else 0.0, # MLX expects 0.0 to disable + top_p=top_p if top_p < 1.0 else MLX_TOP_P_DISABLED, # MLX expects 0.0 to disable top_k=int(top_k) if top_k > 0 else 0, min_p=min_p, min_tokens_to_keep=1, # Always keep at least one token @@ -162,7 +166,7 @@ class MLXModel: if 'max_new_tokens' in state and state['max_new_tokens'] > 0: mlx_params['max_tokens'] = state['max_new_tokens'] else: - mlx_params['max_tokens'] = 512 # Default + mlx_params['max_tokens'] = DEFAULT_MAX_TOKENS # Default # Create custom sampler with advanced parameters sampler = self._create_mlx_sampler(state)