multimodalart HF Staff commited on
Commit
f7b7cd4
·
verified ·
1 Parent(s): 1fee68d

A/B confirmed: the guard's in-process forward pass kills subsequent GPU worker forks — restore the subprocess guard

Browse files
Files changed (1) hide show
  1. app.py +9 -16
app.py CHANGED
@@ -73,22 +73,13 @@ PIPE = None
73
  MANAGER = None
74
  LOAD_ERROR: str | None = None
75
  LOADED_IN: float | None = None
76
- GUARD = None
77
- GUARD_REPO = "hfmlsoc/ncii-light-guard-v01"
78
-
79
-
80
- def load_guard() -> None:
81
- """A 270M CPU text classifier scoring the NCII risk of the prompt on requests carrying a keyframe — the
82
- edit-on-a-real-photo case. It runs before the conditioner call and the denoise booking, so a refused
83
- prompt costs no GPU time on either half."""
84
- global GUARD
85
- from transformers import pipeline
86
-
87
- GUARD = pipeline("text-classification", model=GUARD_REPO, device="cpu")
88
-
89
-
90
  def check_prompt(prompt: str) -> None:
91
- flag = GUARD(prompt, truncation=True)[0]
 
 
 
 
 
92
  if flag["label"] == "ncii":
93
  print(f"[guard] prompt refused (ncii {flag['score']:.2f}): {prompt!r}", flush=True)
94
  raise gr.Error("This prompt was flagged by a content filter and wasn't run.")
@@ -354,7 +345,9 @@ def _fit_keyframe(image_path, current_canvas):
354
  return gr.update(value=image_path), gr.update(value=label)
355
 
356
 
357
- load_guard()
 
 
358
  load_models()
359
 
360
  INTRO = """# MiniMax-H3
 
73
  MANAGER = None
74
  LOAD_ERROR: str | None = None
75
  LOADED_IN: float | None = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  def check_prompt(prompt: str) -> None:
77
+ """The NCII guard, on requests carrying a keyframe — the edit-on-a-real-photo case. It runs before the
78
+ conditioner call and the denoise booking, so a refused prompt costs no GPU time on either half. The
79
+ classifier lives in `ncii_guard`'s spawned subprocess — in the main process it kills every GPU worker."""
80
+ import ncii_guard
81
+
82
+ flag = ncii_guard.classify(prompt)
83
  if flag["label"] == "ncii":
84
  print(f"[guard] prompt refused (ncii {flag['score']:.2f}): {prompt!r}", flush=True)
85
  raise gr.Error("This prompt was flagged by a content filter and wasn't run.")
 
345
  return gr.update(value=image_path), gr.update(value=label)
346
 
347
 
348
+ import ncii_guard
349
+
350
+ ncii_guard.start()
351
  load_models()
352
 
353
  INTRO = """# MiniMax-H3