import sys import os from safetensors.torch import save_file import json # Add the directory containing your modeling.py and configuration.py to the Python path model_dir = "/Users/Goekdeniz.Guelmez@computacenter.com/Library/CloudStorage/OneDrive-COMPUTACENTER/Desktop/mlx-lm/dev" sys.path.append(model_dir) # Import your custom model and configuration classes from modeling_longcat_flash import LongcatFlashForCausalLM from configuration_longcat_flash import LongcatFlashConfig # Load the configuration config_path = os.path.join(model_dir, "config.json") with open(config_path, 'r') as f: config_dict = json.load(f) # Create the configuration object config = LongcatFlashConfig(**config_dict) # Create the model small_model = LongcatFlashForCausalLM(config) # Print parameter count to verify param_count = sum(p.numel() for p in small_model.parameters()) print(f"Model has {param_count:,} parameters") # Convert model to state dict model_state_dict = small_model.state_dict() # Save as safetensors save_file(model_state_dict, os.path.join(model_dir, "model.safetensors")) print("Model saved in safetensors format")