gexinh commited on
Commit
9e3f5be
·
verified ·
1 Parent(s): f019559

Reduce GPU reservation for consecutive visitor questions

Browse files
Files changed (3) hide show
  1. app.py +15 -4
  2. docs/HOSTING.md +10 -2
  3. hf_space/runtime.py +1 -1
app.py CHANGED
@@ -744,6 +744,20 @@ def on_anchor_select(anchor_choice: str, bank: Dict[str, Any], tile_id: str) ->
744
  )
745
 
746
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
747
  def submit_chat(
748
  message: str,
749
  chat_history: List[Dict[str, str]],
@@ -808,10 +822,7 @@ def submit_chat(
808
  runtime["evidence_route"] = answer.evidence_route
809
  except Exception as exc:
810
  if HOSTED_MODE:
811
- status = (
812
- "Live QA could not finish. ZeroGPU capacity, quota, or the model runtime may be unavailable. "
813
- "Please retry later; evidence browsing is still available."
814
- )
815
  assistant_text = status
816
  print(f"Hosted QA failed: {type(exc).__name__}: {exc}", flush=True)
817
  else:
 
744
  )
745
 
746
 
747
+ def _hosted_error_message(error: Exception) -> str:
748
+ text = str(error).lower()
749
+ if "zerogpu" in text and "quota" in text:
750
+ return (
751
+ "Your remaining ZeroGPU allowance is insufficient for this request's reserved GPU duration. "
752
+ "Sign in to Hugging Face to use your account's allowance, or try again after the quota resets. "
753
+ "Evidence browsing is still available."
754
+ )
755
+ return (
756
+ "Live QA could not finish. ZeroGPU capacity, quota, or the model runtime may be unavailable. "
757
+ "Please retry later; evidence browsing is still available."
758
+ )
759
+
760
+
761
  def submit_chat(
762
  message: str,
763
  chat_history: List[Dict[str, str]],
 
822
  runtime["evidence_route"] = answer.evidence_route
823
  except Exception as exc:
824
  if HOSTED_MODE:
825
+ status = _hosted_error_message(exc)
 
 
 
826
  assistant_text = status
827
  print(f"Hosted QA failed: {type(exc).__name__}: {exc}", flush=True)
828
  else:
docs/HOSTING.md CHANGED
@@ -62,13 +62,19 @@ Space build. Startup then explicitly prepares the model using the Spaces SDK's
62
  CUDA emulation, before starting the web interface. Importing the launcher does
63
  not prepare a model; CPU-only startup skips this step entirely.
64
 
65
- The complete question-answering call runs inside `spaces.GPU(duration=120)`.
66
  This includes routing and final answer generation, so both calls use the same
67
  allocated GPU and cached client. The workbench queues one request at a time,
68
  with up to eight queued requests. GPU availability and daily quota are managed
69
  by Hugging Face. An allocation, quota, or inference error leaves evidence
70
  browsing available and asks the visitor to retry later.
71
 
 
 
 
 
 
 
72
  No visitor API key or paid inference endpoint is used. There is no automatic
73
  fallback to an API or to multi-billion-parameter CPU inference.
74
 
@@ -88,6 +94,7 @@ available; a successful CPU preview checks browsing, not GPU inference.
88
  | Model | `Qwen/Qwen2.5-VL-3B-Instruct` |
89
  | Device and precision | `cuda:0`, `bf16` |
90
  | Output limit | 256 generated tokens per model call |
 
91
  | Image budget | 401,408 pixels, about 512 visual tokens for Qwen |
92
  | Question limit | 2,000 characters |
93
  | Host and port | `0.0.0.0:7860` |
@@ -96,7 +103,8 @@ The existing `SLIDEBANK_UI_TREE_DIR`, `SLIDEBANK_BANK_DIR`,
96
  `SLIDEBANK_ARTIFACT_DIR`, `SLIDEBANK_INFER_CONFIG`, `SLIDEBANK_HOST`, and
97
  `SLIDEBANK_PORT` variables can override the corresponding launcher paths or
98
  network settings. `SLIDEBANK_GPU_DURATION` sets a GPU duration between 15 and
99
- 120 seconds. Changing model, path, or hardware settings requires a Space restart.
 
100
 
101
  `allow_remote_download: true` in `configs/hosted.yaml` explicitly permits model
102
  downloads on the hosted path. Local Hugging Face inference remains cache-only
 
62
  CUDA emulation, before starting the web interface. Importing the launcher does
63
  not prepare a model; CPU-only startup skips this step entirely.
64
 
65
+ The complete question-answering call runs inside `spaces.GPU(duration=60)`.
66
  This includes routing and final answer generation, so both calls use the same
67
  allocated GPU and cached client. The workbench queues one request at a time,
68
  with up to eight queued requests. GPU availability and daily quota are managed
69
  by Hugging Face. An allocation, quota, or inference error leaves evidence
70
  browsing available and asks the visitor to retry later.
71
 
72
+ The SDK can scale this reservation for its GPU profile; a 60-second duration
73
+ currently reserves 90 seconds on the Blackwell `large` profile. A request can be
74
+ declined while some allowance remains if that allowance is below the reserved
75
+ duration. The workbench explains this distinction and suggests signing in to
76
+ Hugging Face or returning after the allowance resets.
77
+
78
  No visitor API key or paid inference endpoint is used. There is no automatic
79
  fallback to an API or to multi-billion-parameter CPU inference.
80
 
 
94
  | Model | `Qwen/Qwen2.5-VL-3B-Instruct` |
95
  | Device and precision | `cuda:0`, `bf16` |
96
  | Output limit | 256 generated tokens per model call |
97
+ | GPU duration | 60 seconds for the complete QA call |
98
  | Image budget | 401,408 pixels, about 512 visual tokens for Qwen |
99
  | Question limit | 2,000 characters |
100
  | Host and port | `0.0.0.0:7860` |
 
103
  `SLIDEBANK_ARTIFACT_DIR`, `SLIDEBANK_INFER_CONFIG`, `SLIDEBANK_HOST`, and
104
  `SLIDEBANK_PORT` variables can override the corresponding launcher paths or
105
  network settings. `SLIDEBANK_GPU_DURATION` sets a GPU duration between 15 and
106
+ 120 seconds, defaulting to 60. Changing model, path, or hardware settings requires
107
+ a Space restart.
108
 
109
  `allow_remote_download: true` in `configs/hosted.yaml` explicitly permits model
110
  downloads on the hosted path. Local Hugging Face inference remains cache-only
hf_space/runtime.py CHANGED
@@ -14,7 +14,7 @@ def _enabled(value: str) -> bool:
14
 
15
 
16
  HOSTED_MODE = _enabled(os.environ.get("SLIDEBANK_HOSTED", ""))
17
- GPU_DURATION = max(15, min(120, int(os.environ.get("SLIDEBANK_GPU_DURATION", "120"))))
18
  _spaces = None
19
  _sdk_error = ""
20
  _model_error = ""
 
14
 
15
 
16
  HOSTED_MODE = _enabled(os.environ.get("SLIDEBANK_HOSTED", ""))
17
+ GPU_DURATION = max(15, min(120, int(os.environ.get("SLIDEBANK_GPU_DURATION", "60"))))
18
  _spaces = None
19
  _sdk_error = ""
20
  _model_error = ""