Skip to content

Fix torch import guards in rtdetr_pose to allow execution without torch installed#11

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-execution-issue
Draft

Fix torch import guards in rtdetr_pose to allow execution without torch installed#11
Copilot wants to merge 2 commits intomainfrom
copilot/fix-execution-issue

Conversation

Copy link

Copilot AI commented Feb 22, 2026

Several rtdetr_pose modules imported directly from torch at module level with no fallback, causing ModuleNotFoundError in any environment without torch — even when the code path being exercised has no torch dependency (e.g. argument parsing, run-dir defaulting).

Root cause

The import chain tools/train_minimal.pyrtdetr_pose.train_minimalfactorymodels.backbones hit these unguarded imports before any torch-optional logic could execute:

  • backbone_interface.pyfrom torch import Tensor, nn
  • backbone_projector.pyfrom torch import Tensor, nn
  • models/backbones/blocks.pyimport torch; from torch import nn
  • models/backbones/csp_backbones.pyfrom torch import Tensor, nn
  • models/backbones/torchvision_backbones.pyfrom torch import Tensor

Changes

  • Wrapped all five unguarded torch imports in try/except ImportError stubs, matching the existing pattern in model.py, losses.py, factory.py, etc.
  • backbone_interface.py uses a named stub _NNModuleStub rather than object as the nn.Module fallback — class BaseBackbone(object, ABC) triggers a Python MRO error; a non-object-rooted stub resolves it cleanly:
# backbone_interface.py
try:
    from torch import Tensor, nn
except ImportError:
    class _NNModuleStub:
        pass
    Tensor = None
    nn = SimpleNamespace(Module=_NNModuleStub)

class BaseBackbone(nn.Module, ABC):  # MRO valid with stub, broken with object
    ...

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…errors

Co-authored-by: thinksyncs <42225585+thinksyncs@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with code execution Fix torch import guards in rtdetr_pose to allow execution without torch installed Feb 22, 2026
Copilot AI requested a review from thinksyncs February 22, 2026 08:29
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.

2 participants