MCPcopy Create free account
hub / github.com/OpenMOSS/MOSS-TTS / resolve_attn_implementation

Function resolve_attn_implementation

clis/moss_tts_app.py:147–171  ·  view source on GitHub ↗
(requested: str, device: torch.device, dtype: torch.dtype)

Source from the content-addressed store, hash-verified

145
146
147def resolve_attn_implementation(requested: str, device: torch.device, dtype: torch.dtype) -> str | None:
148 requested_norm = (requested or "").strip().lower()
149
150 if requested_norm in {"none"}:
151 return None
152
153 if requested_norm not in {"", "auto"}:
154 return requested
155
156 # Prefer FlashAttention 2 when package + device conditions are met.
157 if (
158 device.type == "cuda"
159 and importlib.util.find_spec("flash_attn") is not None
160 and dtype in {torch.float16, torch.bfloat16}
161 ):
162 major, _ = torch.cuda.get_device_capability(device)
163 if major >= 8:
164 return "flash_attention_2"
165
166 # CUDA fallback: use PyTorch SDPA kernels.
167 if device.type == "cuda":
168 return "sdpa"
169
170 # CPU fallback.
171 return "eager"
172
173
174def detect_text_language(text: str) -> str:

Callers 2

load_backendFunction · 0.70
mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected