Files
wehub-resource-sync caf324b09d
tests / check_code_quality (push) Waiting to run
tests / tests (ubuntu-latest, 3.10) (push) Blocked by required conditions
tests / tests (ubuntu-latest, 3.11) (push) Blocked by required conditions
Build documentation / build (push) Waiting to run
Deploy "method_comparison" Gradio to Spaces / deploy (push) Waiting to run
Deploy "PEFT shop" Gradio app to Spaces / deploy (push) Waiting to run
tests on transformers main / tests (push) Waiting to run
tests / tests (ubuntu-latest, 3.12) (push) Blocked by required conditions
tests / tests (ubuntu-latest, 3.13) (push) Blocked by required conditions
tests / tests (windows-latest, 3.10) (push) Blocked by required conditions
tests / tests (windows-latest, 3.11) (push) Blocked by required conditions
tests / tests (windows-latest, 3.12) (push) Blocked by required conditions
tests / tests (windows-latest, 3.13) (push) Blocked by required conditions
Secret Leaks / trufflehog (push) Waiting to run
CI security linting / zizmor latest via Cargo (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:24:42 +08:00

49 lines
1.6 KiB
Python

import torch
from peft.tuners._buffer_dict import BufferDict
class TestBufferDict:
def test_init_from_dict_works(self):
bd = BufferDict(
{
"default": torch.randn(10, 2),
}
)
def test_update_from_other_bufferdict(self):
default_tensor = torch.randn(10, 2)
non_default_tensor = torch.randn(10, 2)
bd1 = BufferDict({"default": default_tensor})
bd2 = BufferDict({"non_default": non_default_tensor})
bd1.update(bd2)
assert set(bd1.keys()) == {"default", "non_default"}
assert torch.allclose(bd1["default"], default_tensor)
assert torch.allclose(bd1["non_default"], non_default_tensor)
def test_update_from_dict(self):
default_tensor = torch.randn(10, 2)
non_default_tensor = torch.randn(10, 2)
bd1 = BufferDict({"default": default_tensor})
d1 = {"non_default": non_default_tensor}
bd1.update(d1)
assert set(bd1.keys()) == {"default", "non_default"}
assert torch.allclose(bd1["default"], default_tensor)
assert torch.allclose(bd1["non_default"], non_default_tensor)
def test_update_from_dict_items(self):
default_tensor = torch.randn(10, 2)
non_default_tensor = torch.randn(10, 2)
bd1 = BufferDict({"default": default_tensor})
d1 = {"non_default": non_default_tensor}
bd1.update(d1.items())
assert set(bd1.keys()) == {"default", "non_default"}
assert torch.allclose(bd1["default"], default_tensor)
assert torch.allclose(bd1["non_default"], non_default_tensor)