RightNow-Mini / train /merge_test.py
Jr23xd23's picture
Upload 13 files
aa1df78 verified
Raw History Blame Contribute Delete
1.65 kB
"""Check the road a fine-tuned model takes after training, before the training itself: adapters, merge, save.
python train/merge_test.py --model /data/train/mini/models/Inkling-2-Mini --out /data/train/mini/models/mergetest-16bit
It attaches fresh adapters (which change nothing: their second matrix starts at zero) and writes the merged 16-bit
model. Serving that folder with the engine then shows whether a merged model loads and answers. A check of the
tools, never a result.
"""
import argparse
import json
import os
import time
from unsloth import FastModel # noqa: E402
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--model", required=True)
ap.add_argument("--out", required=True)
a = ap.parse_args()
t0 = time.time()
model, tok = FastModel.from_pretrained(model_name=a.model, max_seq_length=4096, load_in_4bit=False, full_finetuning=False)
model = FastModel.get_peft_model(model, finetune_vision_layers=False, finetune_language_layers=True, finetune_attention_modules=True,
finetune_mlp_modules=True, r=16, lora_alpha=16, lora_dropout=0, bias="none", random_state=3407)
t1 = time.time()
model.save_pretrained_merged(a.out, tok, save_method="merged_16bit")
files = {f: os.path.getsize(os.path.join(a.out, f)) for f in sorted(os.listdir(a.out))}
print("MERGE_TEST", json.dumps({"load_s": round(t1 - t0, 1), "merge_s": round(time.time() - t1, 1),
"gb": round(sum(files.values()) / 1e9, 2), "files": {k: v for k, v in files.items() if v > 1e6 or k.endswith(".json")}}))
if __name__ == "__main__":
main()