Fixes for saving the gemma tokenizer
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
#SIA_INSTALL_NO_WEB=1
|
||||
SIA_INSTALL_NO_NOTEBOOK=1
|
||||
#SIA_INSTALL_NO_CORE=1
|
||||
SIA_INSTALL_NO_ITB=1
|
||||
#SIA_INSTALL_NO_ITB=1
|
||||
SIA_INSTALL_NO_MISTRAL_INFER=1
|
||||
#SIA_INSTALL_NO_GEMMA_INFER=1
|
||||
#SIA_INSTALL_NO_GEMMA_TRAIN=1
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
#SIA_INSTALL_NO_WEB=1
|
||||
#SIA_INSTALL_NO_LLAMA_CPP=1
|
||||
#SIA_INSTALL_NO_NOTEBOOK=1
|
||||
#SIA_INSTALL_NO_CORE=1
|
||||
#SIA_INSTALL_NO_ITB=1
|
||||
@@ -20,6 +21,12 @@ if [ -z "${SIA_INSTALL_NO_WEB}" ]; then
|
||||
)
|
||||
fi
|
||||
|
||||
if [ -z "${SIA_INSTALL_NO_LLAMA_CPP}" ]; then
|
||||
echo "Installing venv for llama.cpp"
|
||||
python3 -m venv /root/venvs/llama_cpp
|
||||
/root/venvs/llama_cpp/bin/pip install /root/sia/modules/llama.cpp
|
||||
fi
|
||||
|
||||
if [ -z "${SIA_INSTALL_NO_NOTEBOOK}" ]; then
|
||||
echo "Installing venv for running notebooks"
|
||||
python3 -m venv /root/venvs/notebook
|
||||
|
||||
@@ -14,4 +14,6 @@ fi
|
||||
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
gemma_train --model "google/gemma-3-12b-it" --output-dir "$OUTPUT_DIR"
|
||||
gemma_train --model "google/gemma-3-12b-it" --output-dir "$OUTPUT_DIR"
|
||||
cp "$OUTPUT_DIR"/tokenizer/* "$OUTPUT_DIR"/merged/
|
||||
llama-convert-hf-to-gguf --outfile "$OUTPUT_DIR/model.gguf" --outtype q8_0 "$OUTPUT_DIR/merged"
|
||||
@@ -8,13 +8,17 @@ version = "0.1.0"
|
||||
requires-python = ">=3.8"
|
||||
|
||||
dependencies = [
|
||||
"accelerate>=0.26.0",
|
||||
"bitsandbytes>=0.45.0",
|
||||
"llama-cpp-scripts @ file:///root/sia/modules/llama.cpp",
|
||||
"accelerate==1.4.0",
|
||||
"bitsandbytes==0.45.3",
|
||||
"datasets==3.3.2",
|
||||
"evaluate==0.4.3",
|
||||
"llm_engine_utils @ file:///root/sia/lib/llm_engine_utils",
|
||||
"trl>=0.17.0",
|
||||
"peft>=0.15.0",
|
||||
"peft==0.14.0",
|
||||
"python-dotenv>=1.0.0",
|
||||
"sentencepiece>=0.2.0",
|
||||
"torch>=2.4.0",
|
||||
"transformers>=4.51.3",
|
||||
"trl==0.15.2",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
@@ -13,11 +13,13 @@ def main():
|
||||
config = Config()
|
||||
train(config)
|
||||
merge(config)
|
||||
os.system(f"cp -r {config.output_dir}/tokenizer/* {config.output_dir}/merged")
|
||||
convert_to_gguf(config)
|
||||
|
||||
def train(config: Config):
|
||||
tokenizer = AutoTokenizer.from_pretrained(config.model, token=config.api_key)
|
||||
tokenizer = AutoTokenizer.from_pretrained(
|
||||
config.model,
|
||||
token=config.api_key,
|
||||
trust_remote_code=True,
|
||||
)
|
||||
tokenizer.save_pretrained(config.output_dir/"tokenizer")
|
||||
|
||||
bnb_config = BitsAndBytesConfig(
|
||||
@@ -90,62 +92,6 @@ def merge(config: Config):
|
||||
safe_serialization=True
|
||||
)
|
||||
|
||||
def convert_to_gguf(config: Config):
|
||||
"""Convert the merged model to GGUF format using llama.cpp's convert_hf_to_gguf script."""
|
||||
print("Converting merged model to GGUF format...")
|
||||
|
||||
# Add path to llama.cpp directory
|
||||
sys.path.append("./llama.cpp")
|
||||
|
||||
try:
|
||||
# Import the necessary components from the conversion script
|
||||
from convert_hf_to_gguf import ModelBase, gguf, ModelType
|
||||
|
||||
# Set up paths
|
||||
dir_model = config.output_dir / "merged"
|
||||
fname_out = config.output_dir / "model.gguf"
|
||||
output_type = gguf.LlamaFileType.MOSTLY_Q8_0 # Using Q8_0 quantization
|
||||
|
||||
# Run the conversion with torch inference mode
|
||||
with torch.inference_mode():
|
||||
# Load hyperparameters
|
||||
hparams = ModelBase.load_hparams(dir_model)
|
||||
model_architecture = hparams["architectures"][0]
|
||||
model_type = ModelType.TEXT
|
||||
|
||||
print(f"Model architecture: {model_architecture}")
|
||||
|
||||
try:
|
||||
# Get the appropriate model class
|
||||
model_class = ModelBase.from_model_architecture(model_architecture, model_type=model_type)
|
||||
|
||||
# Create model instance
|
||||
model_instance = model_class(
|
||||
dir_model,
|
||||
output_type,
|
||||
fname_out,
|
||||
is_big_endian=False,
|
||||
use_temp_file=False,
|
||||
eager=False
|
||||
)
|
||||
|
||||
# Export the model
|
||||
print(f"Exporting model to GGUF format...")
|
||||
model_instance.write()
|
||||
print(f"Model successfully exported to {model_instance.fname_out}")
|
||||
|
||||
except NotImplementedError:
|
||||
print(f"Error: Model architecture {model_architecture} is not supported for GGUF conversion")
|
||||
print("Skipping GGUF conversion")
|
||||
|
||||
except ImportError as e:
|
||||
print(f"Error importing conversion script: {e}")
|
||||
print("Make sure llama.cpp is properly installed and accessible")
|
||||
print("Skipping GGUF conversion")
|
||||
except Exception as e:
|
||||
print(f"Error during GGUF conversion: {e}")
|
||||
print("Skipping GGUF conversion")
|
||||
|
||||
def format_sia_example(example):
|
||||
return example['messages'].removeprefix("<bos>")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user