Revert to use_cache=False (eager attn also broken); hide all audio UI
Browse files- llm/zerogpu_backend.py +7 -10
- ui/web/index.html +10 -11
llm/zerogpu_backend.py
CHANGED
|
@@ -79,11 +79,6 @@ def _load_model() -> None:
|
|
| 79 |
torch_dtype=torch.bfloat16,
|
| 80 |
trust_remote_code=True,
|
| 81 |
low_cpu_mem_usage=True,
|
| 82 |
-
# sdpa hits a K/V-length mismatch inside the bundled custom
|
| 83 |
-
# modeling code on current transformers. Eager attention takes a
|
| 84 |
-
# different forward path that doesn't trigger that bug, which lets
|
| 85 |
-
# us keep use_cache=True for fast O(n) decoding.
|
| 86 |
-
attn_implementation="eager",
|
| 87 |
)
|
| 88 |
model.eval()
|
| 89 |
_model = model
|
|
@@ -132,10 +127,12 @@ def _generate_on_gpu(
|
|
| 132 |
"max_new_tokens": max_new_tokens,
|
| 133 |
"do_sample": do_sample,
|
| 134 |
"pad_token_id": _tokenizer.eos_token_id,
|
| 135 |
-
#
|
| 136 |
-
#
|
| 137 |
-
#
|
| 138 |
-
|
|
|
|
|
|
|
| 139 |
}
|
| 140 |
if do_sample:
|
| 141 |
gen_kwargs["temperature"] = temperature
|
|
@@ -188,7 +185,7 @@ def _maybe_inject_no_think(messages: list[dict[str, Any]]) -> list[dict[str, Any
|
|
| 188 |
# slot ceiling, anything above ~256 tokens risks getting aborted mid-stream.
|
| 189 |
# Witness chat and short story segments easily fit; longer chunks (full case
|
| 190 |
# briefings) will be truncated. Worth accepting for a working demo.
|
| 191 |
-
_ZEROGPU_MAX_TOKENS = int(os.getenv("PHANTOM_GRID_ZEROGPU_MAX_TOKENS", "
|
| 192 |
|
| 193 |
|
| 194 |
def chat_completion(
|
|
|
|
| 79 |
torch_dtype=torch.bfloat16,
|
| 80 |
trust_remote_code=True,
|
| 81 |
low_cpu_mem_usage=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
)
|
| 83 |
model.eval()
|
| 84 |
_model = model
|
|
|
|
| 127 |
"max_new_tokens": max_new_tokens,
|
| 128 |
"do_sample": do_sample,
|
| 129 |
"pad_token_id": _tokenizer.eos_token_id,
|
| 130 |
+
# BOTH sdpa AND eager attention paths in the bundled modeling_minicpm.py
|
| 131 |
+
# have cache_utils-API drift bugs (sdpa: K/V length mismatch; eager:
|
| 132 |
+
# query-length assertion). Disabling KV cache is the only working path.
|
| 133 |
+
# Trade-off: O(n^2) per step. Mitigation: cap max_new_tokens hard so
|
| 134 |
+
# one generation fits the ZeroGPU 120 s slot.
|
| 135 |
+
"use_cache": False,
|
| 136 |
}
|
| 137 |
if do_sample:
|
| 138 |
gen_kwargs["temperature"] = temperature
|
|
|
|
| 185 |
# slot ceiling, anything above ~256 tokens risks getting aborted mid-stream.
|
| 186 |
# Witness chat and short story segments easily fit; longer chunks (full case
|
| 187 |
# briefings) will be truncated. Worth accepting for a working demo.
|
| 188 |
+
_ZEROGPU_MAX_TOKENS = int(os.getenv("PHANTOM_GRID_ZEROGPU_MAX_TOKENS", "128"))
|
| 189 |
|
| 190 |
|
| 191 |
def chat_completion(
|
ui/web/index.html
CHANGED
|
@@ -237,9 +237,9 @@
|
|
| 237 |
<label class="settings-wide">
|
| 238 |
Text AI Backend
|
| 239 |
<select id="providerSetting">
|
| 240 |
-
<option value="
|
|
|
|
| 241 |
<option value="external_llama_cpp_server">User-started llama.cpp server</option>
|
| 242 |
-
<option value="minicpm_omni">OpenBMB MiniCPM-o (voice; may drift to Chinese)</option>
|
| 243 |
</select>
|
| 244 |
</label>
|
| 245 |
<div id="customModelSettings" class="settings-subgrid settings-wide" hidden>
|
|
@@ -318,18 +318,17 @@
|
|
| 318 |
GPU Device
|
| 319 |
<select id="gpuDeviceSetting"></select>
|
| 320 |
</label>
|
| 321 |
-
<label>
|
| 322 |
Voice in Text Chat
|
| 323 |
<select id="witnessChatTtsSetting">
|
| 324 |
-
<option value="
|
| 325 |
-
<option value="0">Off — text only, fast</option>
|
| 326 |
</select>
|
| 327 |
</label>
|
| 328 |
<label>
|
| 329 |
GPU Layers
|
| 330 |
<input id="gpuLayersSetting" type="text" placeholder="auto, 0, or an explicit count" autocomplete="off" />
|
| 331 |
</label>
|
| 332 |
-
<label>
|
| 333 |
Witness Voice Directory
|
| 334 |
<input id="voiceDirSetting" type="text" autocomplete="off" />
|
| 335 |
</label>
|
|
@@ -373,11 +372,11 @@
|
|
| 373 |
<div class="witness-summary" id="witnessSummary"></div>
|
| 374 |
<div class="witness-transcript" id="witnessTranscript" aria-live="polite"></div>
|
| 375 |
<footer>
|
| 376 |
-
<div class="speech-controls">
|
| 377 |
-
<button id="autoSpeechButton" type="button">Start Auto Speech</button>
|
| 378 |
-
<button id="pushToTalkButton" type="button">Hold to Talk</button>
|
| 379 |
-
<button id="stopAudioButton" type="button">Stop Voice</button>
|
| 380 |
-
<meter id="micLevel" min="0" max="1" value="0"></meter>
|
| 381 |
</div>
|
| 382 |
<div class="text-chat-row">
|
| 383 |
<textarea id="witnessMessage" placeholder="Ask the witness a question..."></textarea>
|
|
|
|
| 237 |
<label class="settings-wide">
|
| 238 |
Text AI Backend
|
| 239 |
<select id="providerSetting">
|
| 240 |
+
<option value="zerogpu_transformers">ZeroGPU transformers (this Space)</option>
|
| 241 |
+
<option value="llama_cpp_server">Local GGUF via llama.cpp</option>
|
| 242 |
<option value="external_llama_cpp_server">User-started llama.cpp server</option>
|
|
|
|
| 243 |
</select>
|
| 244 |
</label>
|
| 245 |
<div id="customModelSettings" class="settings-subgrid settings-wide" hidden>
|
|
|
|
| 318 |
GPU Device
|
| 319 |
<select id="gpuDeviceSetting"></select>
|
| 320 |
</label>
|
| 321 |
+
<label hidden>
|
| 322 |
Voice in Text Chat
|
| 323 |
<select id="witnessChatTtsSetting">
|
| 324 |
+
<option value="0">Off — text only</option>
|
|
|
|
| 325 |
</select>
|
| 326 |
</label>
|
| 327 |
<label>
|
| 328 |
GPU Layers
|
| 329 |
<input id="gpuLayersSetting" type="text" placeholder="auto, 0, or an explicit count" autocomplete="off" />
|
| 330 |
</label>
|
| 331 |
+
<label hidden>
|
| 332 |
Witness Voice Directory
|
| 333 |
<input id="voiceDirSetting" type="text" autocomplete="off" />
|
| 334 |
</label>
|
|
|
|
| 372 |
<div class="witness-summary" id="witnessSummary"></div>
|
| 373 |
<div class="witness-transcript" id="witnessTranscript" aria-live="polite"></div>
|
| 374 |
<footer>
|
| 375 |
+
<div class="speech-controls" hidden>
|
| 376 |
+
<button id="autoSpeechButton" type="button" hidden>Start Auto Speech</button>
|
| 377 |
+
<button id="pushToTalkButton" type="button" hidden>Hold to Talk</button>
|
| 378 |
+
<button id="stopAudioButton" type="button" hidden>Stop Voice</button>
|
| 379 |
+
<meter id="micLevel" min="0" max="1" value="0" hidden></meter>
|
| 380 |
</div>
|
| 381 |
<div class="text-chat-row">
|
| 382 |
<textarea id="witnessMessage" placeholder="Ask the witness a question..."></textarea>
|