Skip to content

Fix setup.py #19

Description

@silentchaostheory

There are install issues because torch is imported in the setup.py of the project but it is not in the minimum environment by default. This results in pip install -e . failing for a working environment with torch listed when pip list is run.

To resolve this, I commented out these imports:

import torch
from torch.utils.cpp_extension import (BuildExtension, CppExtension,
                                       CUDAExtension)

And preformed them in a try catch. The build should safely fail later when the module cannot be imported successfully but allows the build to complete gracefully until that time.

# --- START OF NEW CODE ---
try:
    import torch
    from torch.utils.cpp_extension import (BuildExtension, CppExtension,
                                            CUDAExtension)
    # Define placeholder class that acts as a real class
    class BuildExtensionPlaceholder(BuildExtension):
        pass

except ImportError:
    # --- Safe Fallback Classes if torch is not found ---
    class ExtensionPlaceholder(object):
        def __init__(self, *args, **kwargs):
            pass
        def __call__(self, *args, **kwargs):
            return {}

    class BuildExtensionPlaceholder(object):
        def __init__(self, *args, **kwargs):
            pass
        def run(self):
            print("Warning: Skipping custom C++/CUDA extension build because PyTorch could not be imported.")

    # Assign placeholders
    CUDAExtension = ExtensionPlaceholder
    CppExtension = ExtensionPlaceholder
    BuildExtension = BuildExtensionPlaceholder

    # Define a mock torch object for make_cuda_ext's use
    class MockTorch:
        @staticmethod
        def cuda():
            class MockCuda:
                @staticmethod
                def is_available():
                    return False
            return MockCuda
    torch = MockTorch()

This was provided by Gemini so please try this in a testing environment if yours has already successfully run the training script.

You can also add this argument to the setup() parameters to allow for successful build when torch is not available and CPU only will be used.
cmdclass={'build_ext': BuildExtensionPlaceholder},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions