delimitter's picture
Add Makefile: merge + convert + ollama quickstart
0de96b3 verified
Raw
History Blame Contribute Delete
2.24 kB
.PHONY: setup merge convert pull run clean
MODEL_NAME := synoema-coder-3b-v2
BASE_MODEL := Qwen/Qwen2.5-Coder-3B-Instruct
ADAPTER_HF := delimitter/synoema-coder-3b-v2
OLLAMA_TAG := synoema-coder-3b-v2
MERGED_DIR := ./$(MODEL_NAME)-merged
GGUF_FILE := ./$(MODEL_NAME)-q4km.gguf
## Install Python dependencies
setup:
pip install transformers peft torch accelerate huggingface_hub
# For GGUF conversion: pip install llama-cpp-python
# Or use llama.cpp directly: https://github.com/ggerganov/llama.cpp
## Merge LoRA adapter into base model
merge:
@echo "Merging $(ADAPTER_HF) into $(BASE_MODEL)..."
python3 -c "\
from transformers import AutoModelForCausalLM, AutoTokenizer; \
from peft import PeftModel; import torch; \
model = AutoModelForCausalLM.from_pretrained('$(BASE_MODEL)', torch_dtype=torch.float16); \
model = PeftModel.from_pretrained(model, '$(ADAPTER_HF)'); \
model = model.merge_and_unload(); \
model.save_pretrained('$(MERGED_DIR)'); \
AutoTokenizer.from_pretrained('$(BASE_MODEL)').save_pretrained('$(MERGED_DIR)'); \
print('Saved merged model to $(MERGED_DIR)')"
## Convert merged model to GGUF Q4_K_M (requires llama.cpp)
convert: merge
@echo "Converting to GGUF Q4_K_M..."
@[ -f convert_hf_to_gguf.py ] || (echo "Download llama.cpp convert script:" && \
echo " wget https://raw.githubusercontent.com/ggerganov/llama.cpp/master/convert_hf_to_gguf.py" && exit 1)
python3 convert_hf_to_gguf.py $(MERGED_DIR) --outtype q4_k_m --outfile $(GGUF_FILE)
@echo "GGUF ready: $(GGUF_FILE)"
## Create Ollama model from GGUF (sets Synoema system prompt)
pull: convert
@echo "Creating Ollama model $(OLLAMA_TAG)..."
@printf 'FROM $(GGUF_FILE)\nSYSTEM \"\"\"You are Synoema programming language assistant. Synoema is a strongly typed functional language with Hindley-Milner type inference, formal contracts (requires/ensures), pattern matching, and IoT/WASM support. Always produce valid Synoema code.\"\"\"\n' > Modelfile
ollama create $(OLLAMA_TAG) -f Modelfile
@rm Modelfile
@echo "Done. Run: make run"
## Run interactive chat
run:
ollama run $(OLLAMA_TAG)
## Remove model from Ollama and clean temp files
clean:
ollama rm $(OLLAMA_TAG) 2>/dev/null || true
rm -rf $(MERGED_DIR) $(GGUF_FILE) Modelfile