这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@jiqing-feng
Copy link
Contributor

@jiqing-feng jiqing-feng commented Oct 11, 2025

The test: pytest -rA tests/test_common_gpu.py::PeftGPUCommonTests::test_8bit_merge_lora_with_bias failed on XPU due to the accuracy check. After investigation, I found it is due to the accident of the seed. To prove it, I selected seeds from 0 to 100 and see if the accuracy can pass.

import torch
import torch.nn.functional as F
from transformers import AutoModelForCausalLM, BitsAndBytesConfig
from peft import LoraConfig, get_peft_model

def main(seed):
    torch.manual_seed(seed)
    model = AutoModelForCausalLM.from_pretrained(
        "facebook/opt-125m",
        quantization_config=BitsAndBytesConfig(load_in_8bit=True),
    )
    random_input = torch.LongTensor([[1, 0, 1, 0, 1, 0]]).to(model.device)
    out_base = F.softmax(model(random_input).logits, dim=-1)
    config = LoraConfig(
        r=8,
        init_lora_weights=False,
        lora_bias=True,
    )
    model = get_peft_model(model, config)
    with torch.inference_mode():
        out_before_merge = F.softmax(model(random_input).logits, dim=-1)

    model.merge_and_unload()
    with torch.inference_mode():
        out_after_merge = F.softmax(model(random_input).logits, dim=-1)

    atol = 1e-3
    rtol = 1
    if torch.allclose(out_before_merge, out_after_merge, atol=atol, rtol=rtol):
        seed_pass.append(seed)
        print(f"seed: {seed} " + "pass " + "="*10)
    else:
        seed_fail.append(seed)
        print(f"seed: {seed} " + "fail " + "e"*20)

if __name__ == "__main__":
    seed_pass = []
    seed_fail = []
    for seed in range(100):
        main(seed)
    print(f"passed seeds: {seed_pass}")
    print(f"failed seeds: {seed_fail}")

Output on CUDA (A100):

passed seeds: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
failed seeds: [29, 34]

Output on XPU:

passed seeds: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
failed seeds: [29, 34, 41]

So I select a different seed so the XPU and CUDA checks can all pass.

Hi @BenjaminBossan . Would you please review this PR? Thanks!

cc @yao-matrix

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting discovery, and bad luck with the previous seed. Changes LGTM, failing CI is unrelated.

@BenjaminBossan BenjaminBossan merged commit 2410f45 into huggingface:main Oct 13, 2025
5 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants