|
|
import torch |
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer |
|
|
import os |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
base_model_id = "Qwen/Qwen1.5-7B" |
|
|
|
|
|
|
|
|
checkpoint_path = "/path/to/your/checkpoint.pth" |
|
|
|
|
|
|
|
|
|
|
|
output_dir = "../my_pretrain_for_eval" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(f"Loading base model architecture from: {base_model_id}") |
|
|
|
|
|
model = AutoModelForCausalLM.from_pretrained(base_model_id, trust_remote_code=True) |
|
|
tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True) |
|
|
|
|
|
|
|
|
|
|
|
print(f"Loading training checkpoint from: {checkpoint_path}") |
|
|
|
|
|
checkpoint = torch.load(checkpoint_path, map_location='cpu') |
|
|
|
|
|
|
|
|
|
|
|
model_weights = checkpoint['model'] |
|
|
|
|
|
|
|
|
|
|
|
print("Loading fine-tuned weights into the model...") |
|
|
model.load_state_dict(model_weights) |
|
|
print("Weights loaded successfully.") |
|
|
|
|
|
|
|
|
|
|
|
print(f"Saving model and tokenizer to: {output_dir}") |
|
|
os.makedirs(output_dir, exist_ok=True) |
|
|
|
|
|
|
|
|
model.save_pretrained(output_dir) |
|
|
|
|
|
|
|
|
tokenizer.save_pretrained(output_dir) |
|
|
|
|
|
print("Conversion complete!") |
|
|
print(f"Your model is now ready for evaluation at: {output_dir}") |