--- title: Llm Moderation Testing emoji: 🦀 colorFrom: gray colorTo: blue sdk: gradio sdk_version: 6.0.0 app_file: app.py pinned: false license: apache-2.0 short_description: A model to test different models assessing content policies hf_oauth: true hf_oauth_scopes: - read-repos - write-repos - manage-repos - inference-api --- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference ## Dedicated-endpoint classifier models Most models run through the HF Inference Router (pay-per-token, nothing to host). Three classifier models are **not** served by the router and each need their own HF Inference Endpoint. They appear in the model dropdown but raise a clear error until the endpoint + secrets are configured. | Model | Serving | Recommended GPU | ~$/hr | |---|---|---|---| | PolicyLM-1.7B | Custom handler | T4 16 GB | ~$0.50 | | Shieldstral-1.0-3B | vLLM (OpenAI-compatible) | L4 24 GB | ~$0.80 | | CoPE-B-S1 | Custom SGLang (`/v1/systemone`) | **A100 80 GB** | ~$2.50 | > **Cost / teardown — read this.** Endpoints bill **per minute of uptime**, not per > request. For a short event, deploy + smoke-test the day before, **Pause** all three > (paused = no compute billing, weights stay cached), **Resume** ~30 min before, then > **Pause or Delete immediately afterward**. A forgotten CoPE-B-S1 A100 is ~$2.50/hr ≈ > $60/day. Prices above are approximate HF list prices (AWS A100 ×1) — confirm at > https://huggingface.co/pricing. ### Shieldstral-1.0-3B (`mistralai/Shieldstral-1.0-3B`) - Deploy to a GPU Inference Endpoint with the **vLLM** (OpenAI-compatible) container on an **L4 (24 GB)**. No custom handler needed. - Set Space secrets: - `SHIELDSTRAL_ENDPOINT_URL` — the endpoint base URL ending in `/v1` - `SHIELDSTRAL_INFERENCE_TOKEN` — a token with access to the endpoint - `SHIELDSTRAL_SERVED_MODEL_NAME` — *(optional)* if the endpoint serves under a name other than `mistralai/Shieldstral-1.0-3B` - The app calls chat completions with `max_tokens=1, logprobs=True, top_logprobs=20`, softmaxes the yes/no logprobs into a violation probability (threshold 0.5), and shows the score in the Reasoning Trace panel. ### PolicyLM-1.7B (`musubilabs/policylm-1.7b`) - Not OpenAI/vLLM-compatible — deploy as a **Custom** Inference Endpoint on a **T4 (16 GB)** using the provided `policylm_handler.py` (rename to `handler.py` in the endpoint repo). See the deployment steps in that file's docstring. - Set Space secrets: - `POLICYLM_ENDPOINT_URL` — the endpoint URL - `POLICYLM_INFERENCE_TOKEN` — a token with access to the endpoint - The handler returns `{flagged, max_score, categories[]}`; the app maps `flagged` to the violation label and lists per-category scores in the Reasoning Trace panel. #### Structured rules (per-rule scores) The **Policy Definition** tab has a **Structured Rules** editor where a policy is authored as discrete rules, each with three fields that map 1:1 onto PolicyLM's `Category` constructor: | Editor field | PolicyLM kwarg | |---|---| | ✅ Flag this | `violation_rule` | | 🚫 Don't flag this | `not_violation_rule` | | ⚠️ Exception | `exception_override` | When any rule has content, those rules become the source of truth. They are: - **sent to PolicyLM natively** as discrete categories (one score per rule, and exceptions are read as exceptions rather than as things to flag); and - **rendered to a plain-text policy** that every other model (gpt-oss-safeguard, Shieldstral, CoPE) receives through the normal policy string — so all models are judged on the *same* policy. The editor shows a live count against PolicyLM's limits (**≤16 categories, ≤1,662 policy tokens**; policy + message share 2,048) and warns when either is exceeded. The token figure is an approximate heuristic — swap in `AutoTokenizer.from_pretrained("musubilabs/policylm-1.7b")` in `utils/policy_rules.estimate_policy_tokens` if you want an exact count. > **⚠️ Endpoint redeploy required.** Per-rule scoring needs the updated > `policylm_handler.py` (it now builds one `Category` per rule from an optional > `inputs.categories` list, falling back to the legacy single-category wrap when it's > absent). After editing `policylm_handler.py` here, push it as `handler.py` to your > PolicyLM endpoint repo and redeploy the endpoint. Until then the endpoint runs the > old handler and will keep returning a single overall score. No Space secrets change. ### CoPE-B-S1 (`zentropi-ai/cope-b-s1`) CoPE-B-S1 is a **policy-steerable decision model** (Gemma-4 26B-A4B MoE base, ~25.2B total / ~3.8B active), **not** a standard generate() LLM. It implements the **System One** decision spec and is read via *pooled prefill slots* (no tokens generated), so it is **not** vLLM/OpenAI-compatible — it needs Zentropi's custom SGLang server. - Deploy the **`zentropiai/cope-s1-sglang`** container (pin a real tag, e.g. **`:v0.1.6`** — there is no `:latest`) on an **A100 80 GB**, with env `MODEL=/repository` (so HF's mounted copy is used instead of re-downloading) and the model repo `zentropi-ai/cope-b-s1` as the endpoint repository. Port **80**, health route `/health`. First deploy downloads ~50 GB, so allow **15–30+ min**. - Set Space secrets: - `COPE_B_ENDPOINT_URL` — the endpoint **root** URL (the app appends `/v1/systemone`; do **not** add `/v1`) - `COPE_B_INFERENCE_TOKEN` — a token with access to the endpoint - The app (`run_cope_b`) POSTs a System One request to `/v1/systemone`: a single `noul` question wrapping the policy (`"Does the content meet the criteria described in the following policy?\n\n"` + policy) with `state.content` = the test content. It reads `answers.q1.noul` = P(violation), thresholds at `COPE_B_THRESHOLD` (0.5) for the label, and shows the probability in the Reasoning Trace panel. - CoPE-B-S1 can answer **up to 26 typed questions in one pass** — a future enhancement could send one `noul` per structured rule for per-rule CoPE scores (mirroring PolicyLM). The current integration judges the whole rendered policy as one question.