{"record":{"id":"a78b3a1d8ccc14eb","repo":"hpcaitech/Open-Sora","slug":"memefficientringattnprocessor-requires-xformers-t","errorCode":null,"errorMessage":"MemEfficientRingAttnProcessor requires xformers, to use it, please install xformers.","messagePattern":"MemEfficientRingAttnProcessor requires xformers, to use it, please install xformers\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"opensora/models/hunyuan_vae/distributed.py","lineNumber":275,"sourceCode":"            Tuple[torch.Tensor, torch.Tensor]: output and log sum exp. Output's shape should be [B, S, N, D]. LSE's shape should be [B, N, S].\n        \"\"\"\n        if MemEfficientRingAttention.ATTN_DONE is None:\n            MemEfficientRingAttention.ATTN_DONE = torch.cuda.Event()\n        if MemEfficientRingAttention.SP_STREAM is None:\n            MemEfficientRingAttention.SP_STREAM = torch.cuda.Stream()\n        out, softmax_lse = MemEfficientRingAttention.apply(\n            q, k, v, sp_group, MemEfficientRingAttention.SP_STREAM, softmax_scale, attn_mask\n        )\n        if return_softmax:\n            return out, softmax_lse\n        return out\n\n\nclass MemEfficientRingAttnProcessor:\n    def __init__(self, sp_group: dist.ProcessGroup):\n        self.sp_group = sp_group\n        if not HAS_XFORMERS:\n            raise ImportError(\"MemEfficientRingAttnProcessor requires xformers, to use it, please install xformers.\")\n\n    def __call__(\n        self,\n        attn: Attention,\n        hidden_states: torch.Tensor,\n        encoder_hidden_states: Optional[torch.Tensor] = None,\n        attention_mask: Optional[torch.Tensor] = None,\n        temb: Optional[torch.Tensor] = None,\n        *args,\n        **kwargs,\n    ) -> torch.Tensor:\n        sp_group = self.sp_group\n        assert sp_group is not None, \"sp_group must be provided for MemEfficientRingAttnProcessor\"\n\n        residual = hidden_states\n        if attn.spatial_norm is not None:\n            hidden_states = attn.spatial_norm(hidden_states, temb)\n","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/hpcaitech/Open-Sora/blob/7ad6a96a135feb81f755c84fb391818718f6beb2/opensora/models/hunyuan_vae/distributed.py#L257-L293","documentation":"MemEfficientRingAttnProcessor implements memory-efficient ring attention for sequence/context parallelism using the xformers memory-efficient attention kernel. Its __init__ checks the HAS_XFORMERS flag and raises ImportError immediately when xformers is not installed in the environment.","triggerScenarios":"Constructing MemEfficientRingAttnProcessor(sp_group) — directly or via a context-parallel setup path that builds ring attention processors — in an environment where `import xformers` failed.","commonSituations":"Running Hunyuan VAE context/sequence parallel inference or training on a box where xformers was never installed, is incompatible with the installed torch/CUDA version, or fails to import due to a broken build.","solutions":["pip install xformers with a version matched to your torch and CUDA version (see xformers release matrix)","If the import fails despite installation, check torch/xformers version compatibility and reinstall the matching pair","Fall back to a non-xformers ring attention processor if one is available in distributed.py"],"exampleFix":"# before\nproc = MemEfficientRingAttnProcessor(sp_group)  # ImportError\n# after\n# pip install xformers\nproc = MemEfficientRingAttnProcessor(sp_group)","handlingStrategy":"validation","validationCode":"try:\n    import xformers  # noqa\n    HAS_XFORMERS = True\nexcept ImportError:\n    HAS_XFORMERS = False\nassert HAS_XFORMERS, \"install xformers matched to your torch/CUDA before using ring attention\"","typeGuard":"def has_xformers() -> bool:\n    try:\n        import xformers  # noqa\n        return True\n    except ImportError:\n        return False","tryCatchPattern":"try:\n    proc = MemEfficientRingAttnProcessor(sp_group)\nexcept ImportError as e:\n    raise RuntimeError(\"pip install xformers (version matched to torch) to use ring attention\") from e","preventionTips":["Pin compatible torch/xformers version pairs in requirements","Feature-detect xformers before enabling context-parallel code paths","Smoke-test distributed setup in CI"],"tags":["xformers","distributed","import-error","dependency"],"backgroundTag":"missing-optional-dependency","analyzedSha":"7ad6a96a135feb81f755c84fb391818718f6beb2","analyzedAt":"2026-08-28T16:58:37.171Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}