16031aae96
CPU tests Workflow / Testing (ubuntu-latest, 3.12) (push) Failing after 1s
CPU tests Workflow / Testing (ubuntu-latest, 3.13) (push) Failing after 0s
Mypy Type Check / Type Check (push) Failing after 0s
Docs/Test WorkFlow / Test docs build (push) Failing after 1s
PR Conflict Labeler / labeling (push) Failing after 1s
Dependency resolution / Resolve [tflite] extra — Python 3.12 (push) Failing after 0s
Smoke Tests / try-all-models (ubuntu-latest, 3.10) (push) Failing after 0s
Smoke Tests / try-all-models (ubuntu-latest, 3.13) (push) Failing after 1s
CPU tests Workflow / build-pkg (push) Failing after 1s
CPU tests Workflow / Testing (ubuntu-latest, 3.10) (push) Failing after 0s
CPU tests Workflow / Testing (ubuntu-latest, 3.11) (push) Failing after 0s
Smoke Tests / try-all-models (macos-latest, 3.10) (push) Has been cancelled
Smoke Tests / try-all-models (macos-latest, 3.13) (push) Has been cancelled
Smoke Tests / try-all-models (windows-latest, 3.10) (push) Has been cancelled
Smoke Tests / try-all-models (windows-latest, 3.13) (push) Has been cancelled
CPU tests Workflow / Testing (macos-latest, 3.10) (push) Has been cancelled
CPU tests Workflow / Testing (macos-latest, 3.13) (push) Has been cancelled
CPU tests Workflow / Testing (windows-latest, 3.10) (push) Has been cancelled
CPU tests Workflow / Testing (windows-latest, 3.13) (push) Has been cancelled
CPU tests Workflow / testing-guardian (push) Has been cancelled
GPU tests Workflow / Testing (push) Has been cancelled
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
# ------------------------------------------------------------------------
|
|
# RF-DETR
|
|
# Copyright (c) 2025 Roboflow. All Rights Reserved.
|
|
# Licensed under the Apache License, Version 2.0 [see LICENSE for details]
|
|
# ------------------------------------------------------------------------
|
|
"""Tests for backbone export behavior."""
|
|
|
|
import sys
|
|
from types import ModuleType
|
|
|
|
from rfdetr.models.backbone.backbone import Backbone
|
|
|
|
|
|
class TestBackboneExport:
|
|
"""Tests for ``Backbone.export``."""
|
|
|
|
def test_export_without_lora_encoder_skips_peft_import_and_warning(self, monkeypatch) -> None:
|
|
"""Non-LoRA exports should not warn just because peft is unavailable."""
|
|
backbone = object.__new__(Backbone)
|
|
backbone.encoder = object()
|
|
warning_messages: list[str] = []
|
|
|
|
monkeypatch.delitem(sys.modules, "peft", raising=False)
|
|
monkeypatch.setattr("rfdetr.models.backbone.backbone.logger.warning", warning_messages.append)
|
|
|
|
backbone.export()
|
|
|
|
assert warning_messages == []
|
|
|
|
def test_export_replaces_peft_encoder_with_merged_encoder(self, monkeypatch) -> None:
|
|
"""Export should replace PEFT wrapper with merged base encoder."""
|
|
|
|
class _MergedEncoder:
|
|
pass
|
|
|
|
class _FakePeftModel:
|
|
def __init__(self) -> None:
|
|
self._merged = _MergedEncoder()
|
|
|
|
def merge_and_unload(self):
|
|
return self._merged
|
|
|
|
peft_module = ModuleType("peft")
|
|
peft_module.PeftModel = _FakePeftModel
|
|
monkeypatch.setitem(sys.modules, "peft", peft_module)
|
|
|
|
backbone = object.__new__(Backbone)
|
|
backbone.encoder = _FakePeftModel()
|
|
|
|
backbone.export()
|
|
|
|
assert isinstance(backbone.encoder, _MergedEncoder)
|