File size: 4,789 Bytes
fa9878d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | #!/bin/bash
# Script to prepare Ollama model for Hugging Face upload
# This script helps export the Ollama model and prepare it for Hugging Face
set -e
MODEL_NAME="llama3-dementia-care:latest"
EXPORT_DIR="./model_export"
CURRENT_DIR=$(pwd)
echo "π Preparing Llama 3 Dementia Care model for Hugging Face upload..."
echo "=================================================="
# Check if Ollama is installed
if ! command -v ollama &> /dev/null; then
echo "β Error: Ollama is not installed or not in PATH"
echo "Please install Ollama first: https://ollama.com"
exit 1
fi
# Check if the model exists
if ! ollama list | grep -q "$MODEL_NAME"; then
echo "β Error: Model $MODEL_NAME not found"
echo "Available models:"
ollama list
exit 1
fi
echo "β
Found model: $MODEL_NAME"
# Create export directory
mkdir -p "$EXPORT_DIR"
cd "$EXPORT_DIR"
echo "π Created export directory: $EXPORT_DIR"
# Export model information
echo "π Exporting model information..."
ollama show "$MODEL_NAME" > model_details.txt
ollama show "$MODEL_NAME" --modelfile > exported_modelfile.txt
echo "π Model details saved to:"
echo " - model_details.txt"
echo " - exported_modelfile.txt"
# Create a README for the export
cat > export_README.md << 'EOF'
# Exported Ollama Model Files
This directory contains the exported files from your Ollama model that need to be converted for Hugging Face.
## Files:
- `model_details.txt` - Detailed model information from Ollama
- `exported_modelfile.txt` - The Modelfile configuration
- `export_README.md` - This file
## Next Steps:
### Option 1: Manual Conversion
1. You'll need to manually extract the model weights from Ollama's blob storage
2. Convert them to PyTorch/Safetensors format
3. Create proper tokenizer files
### Option 2: Use Conversion Tools
1. Install ollama-python: `pip install ollama`
2. Use conversion scripts like:
- https://github.com/ollama/ollama/blob/main/docs/modelfile.md
- Community conversion tools
### Option 3: Re-train/Fine-tune
1. Start with the base Llama 3 8B model from Hugging Face
2. Fine-tune it with your dementia care dataset
3. Upload the fine-tuned model
## Important Notes:
- Ollama stores models in a specific format that may require conversion
- The model weights are typically in `/Users/[username]/.ollama/models/blobs/`
- You may need to use specialized tools to extract and convert the weights
For more information, visit: https://ollama.com/blog/modelfile
EOF
echo "π Created export_README.md with next steps"
# Try to locate the actual model blob
echo "π Locating model blob files..."
OLLAMA_MODELS_DIR="$HOME/.ollama/models"
if [ -d "$OLLAMA_MODELS_DIR" ]; then
echo "π Ollama models directory: $OLLAMA_MODELS_DIR"
# Extract the blob SHA from the Modelfile
BLOB_SHA=$(grep "^FROM" exported_modelfile.txt | grep "sha256" | awk -F'sha256-' '{print $2}')
if [ -n "$BLOB_SHA" ]; then
echo "π Model blob SHA: $BLOB_SHA"
BLOB_PATH="$OLLAMA_MODELS_DIR/blobs/sha256-$BLOB_SHA"
if [ -f "$BLOB_PATH" ]; then
echo "β
Found model blob: $BLOB_PATH"
echo "π Blob size: $(ls -lh "$BLOB_PATH" | awk '{print $5}')"
# Copy blob info to export
echo "Model Blob Information:" > blob_info.txt
echo "SHA256: $BLOB_SHA" >> blob_info.txt
echo "Path: $BLOB_PATH" >> blob_info.txt
echo "Size: $(ls -lh "$BLOB_PATH" | awk '{print $5}')" >> blob_info.txt
echo "Modified: $(ls -l "$BLOB_PATH" | awk '{print $6, $7, $8}')" >> blob_info.txt
else
echo "β Model blob not found at expected location"
fi
else
echo "β Could not extract blob SHA from Modelfile"
fi
else
echo "β Ollama models directory not found"
fi
cd "$CURRENT_DIR"
echo ""
echo "π Export preparation complete!"
echo "=================================================="
echo "π Files exported to: $EXPORT_DIR"
echo ""
echo "β οΈ IMPORTANT: Converting Ollama models to Hugging Face format requires additional steps:"
echo ""
echo "π Conversion Options:"
echo "1. Use ollama-python and conversion tools"
echo "2. Extract and convert model weights manually"
echo "3. Re-train using the base Llama 3 model on Hugging Face"
echo ""
echo "π Resources:"
echo "- Ollama documentation: https://ollama.com/blog/modelfile"
echo "- Hugging Face model upload: https://huggingface.co/docs/transformers/model_sharing"
echo ""
echo "β
Your repository structure is ready for Hugging Face!"
echo "π Repository files created:"
ls -la "$CURRENT_DIR" | grep -E '\.(md|json|txt|py)$|Modelfile|NOTICE'
echo ""
echo "π Next: Upload your repository to Hugging Face and add the converted model weights."
|