|
|
|
|
|
|
|
|
| !pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
|
|
|
|
| from unsloth import FastLanguageModel
|
| import torch
|
|
|
|
|
| model_name = "YOUR_USERNAME/YOUR_REPO_NAME"
|
|
|
| max_seq_length = 2048
|
| dtype = None
|
| load_in_4bit = True
|
|
|
|
|
| model, tokenizer = FastLanguageModel.from_pretrained(
|
| model_name = model_name,
|
| max_seq_length = max_seq_length,
|
| dtype = dtype,
|
| load_in_4bit = load_in_4bit,
|
| )
|
|
|
| print("Model loaded successfully!")
|
| print(f"Model type: {model.config.model_type}")
|
| print(f"Model architecture: {model.config.architectures}")
|
|
|
|
|
| print("Current chat template:")
|
| print(repr(tokenizer.chat_template))
|
|
|
|
|
| print("Starting GGUF conversion...")
|
|
|
|
|
| model.save_pretrained_gguf(
|
| "ollama_converted_model",
|
| tokenizer,
|
| quantization_method = "q4_k_m",
|
| )
|
|
|
| print("Conversion completed!")
|
| print("Files created:")
|
| !ls -la ollama_converted_model/
|
|
|
|
|
| from google.colab import files
|
| import zipfile
|
| import os
|
|
|
|
|
| with zipfile.ZipFile('ollama_model.zip', 'w') as zipf:
|
| for root, dirs, files_list in os.walk('ollama_converted_model'):
|
| for file in files_list:
|
| file_path = os.path.join(root, file)
|
| zipf.write(file_path, os.path.relpath(file_path, 'ollama_converted_model'))
|
|
|
| print("Model packaged! Downloading...")
|
| files.download('ollama_model.zip')
|
|
|
|
|
| print("\n=== Ollama Modelfile content ===")
|
| try:
|
| with open('ollama_converted_model/Modelfile', 'r') as f:
|
| modelfile_content = f.read()
|
| print(modelfile_content)
|
| except FileNotFoundError:
|
| print("Modelfile not found. The model might not have Ollama support.")
|
|
|
| print("\n=== Instructions ===")
|
| print("1. Download the ollama_model.zip file")
|
| print("2. Extract it on your Windows machine")
|
| print("3. Use 'ollama create your-model-name -f Modelfile' to import")
|
| print("4. Run 'ollama run your-model-name' to test")
|
|
|