Skip to content

[Question] Merging 4-bit Checkpoint into Phi-4 Base Model – Model Inference Inconsistent #2510

Closed as not planned

Description

@Close-01

Hi everyone, I followed the Unsloth documentation (https://docs.unsloth.ai/basics/running-and-saving-models/saving-to-vllm) to merge a 4-bit checkpoint (checkpoint-105) into the Phi-4 base model. The process appeared to complete successfully, but when running inference, the model produces outputs that are significantly different from the expected results based on the fine-tuning dataset (4,000 Q&A pairs from 1,000 Thai words with 4 prompt variations each). I'm unsure whether the checkpoint merge into 4-bit format was done correctly or if something went wrong during saving/loading.

Image

Activity

  1. github-actions commented on Jul 1, 2025

    @github-actions
    Contributor

    Is this issue still important to you? Apologies in advance we might have missed this issue as well. For faster response times, please post on our Reddit server - https://www.reddit.com/r/unsloth or our Discord - https://discord.com/invite/unsloth

  2. self-assigned this
    on Oct 8, 2026
  3. danielhanchen commented on Oct 8, 2026

    @danielhanchen
    Member

    Sorry on the delay! The outputs match the base model because of the loading steps, not the merge itself:

    1. Step 6 loads "unsloth/Phi-4" again, which is the original base model, so none of your fine-tuning is used. Point model_name at your saved folder instead.
    2. save_method = "lora" only saves the LoRA adapter, it does not merge anything. Use save_method = "merged_16bit" for a merged model (for vLLM), or "merged_4bit_forced" if you really need 4-bit weights.
    3. load_adapter(..., adapter_name = "Checkpoint-105") after get_peft_model adds the checkpoint as a second adapter, but the active one stays the new, untrained default adapter. You would need Phi4_model.set_adapter("Checkpoint-105").

    The simplest way is to load the checkpoint folder directly, since Unsloth reads the base model from the adapter config:

    from unsloth import FastLanguageModel
    model, tokenizer = FastLanguageModel.from_pretrained(
        model_name = "D:/LLMs/FineTune_Phi_4_Checkpoints_4kRecords/checkpoint-105",
        max_seq_length = 2048,
        load_in_4bit = True,
    )
    FastLanguageModel.for_inference(model)
    
    # Optional: merge for vLLM, then load this folder (not "unsloth/Phi-4")
    model.save_pretrained_merged("D:/LLMs/Phi4_merged_16bit", tokenizer, save_method = "merged_16bit")

    Also make sure you prompt with the same chat template and system prompt you trained with. I checked all three points on the latest Unsloth with a small Phi model: your steps give outputs identical to the base model, while loading the checkpoint folder directly (or calling set_adapter) reproduces the trained adapter's outputs exactly.

    I'll close this for now, but feel free to reopen if you still see a mismatch after loading the checkpoint this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions