File size: 1,407 Bytes
d91766b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from . import metadata
from .metadata import set_fetch_fn_for_attn_metadata, AttnMetaDataBase


# Create a proxy that dynamically accesses fetch_attn_metadata from the metadata module
# This ensures we always get the current value, not a stale copy from __init__.py
class _FetchAttnMetadataProxy:
    """Proxy object that dynamically accesses fetch_attn_metadata from metadata module."""

    def __call__(self, *args, **kwargs):
        return metadata.fetch_attn_metadata(*args, **kwargs)

    def __repr__(self):
        return repr(metadata.fetch_attn_metadata)


fetch_attn_metadata = _FetchAttnMetadataProxy()


def __getattr__(name):
    """Lazy import to avoid circular deps during module init."""
    if name == "Attention":
        try:
            from .attn_impl import Attention

            return Attention
        except Exception as e:
            raise ImportError(f"Failed to import diffulex.attention.attn_impl.Attention: {e}")
    if name == "reference_torch_attention":
        try:
            from .attn_impl import reference_torch_attention

            return reference_torch_attention
        except Exception as e:
            raise ImportError(f"Failed to import diffulex.attention.attn_impl.reference_torch_attention: {e}")
    if name == "fetch_attn_metadata":
        return metadata.fetch_attn_metadata
    raise AttributeError(f"module {__name__} has no attribute {name}")