Spaces:
Running on Zero
Running on Zero
Upload 130 files
Browse files- app.py +28 -11
- obliteratus/abliterate.py +33 -2
- obliteratus/tourney.py +1 -1
app.py
CHANGED
|
@@ -1511,7 +1511,8 @@ def _format_multi_model_results(results: list[dict], context: dict | None = None
|
|
| 1511 |
|
| 1512 |
|
| 1513 |
@spaces.GPU(duration=300)
|
| 1514 |
-
def obliterate(model_choice: str, method_choice: str,
|
|
|
|
| 1515 |
prompt_volume_choice: str, dataset_source_choice: str,
|
| 1516 |
custom_harmful: str, custom_harmless: str,
|
| 1517 |
# Advanced params (sliders)
|
|
@@ -1544,7 +1545,14 @@ def obliterate(model_choice: str, method_choice: str, hub_repo: str,
|
|
| 1544 |
model_id = MODELS.get(model_choice, model_choice)
|
| 1545 |
is_preset = model_choice in MODELS
|
| 1546 |
method = METHODS.get(method_choice, "advanced")
|
| 1547 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1548 |
prompt_volume = PROMPT_VOLUMES.get(prompt_volume_choice, 33)
|
| 1549 |
|
| 1550 |
# Resolve "adaptive" β telemetry-recommended method for this model
|
|
@@ -1594,7 +1602,7 @@ def obliterate(model_choice: str, method_choice: str, hub_repo: str,
|
|
| 1594 |
|
| 1595 |
# Early validation: Hub repo format + HF_TOKEN
|
| 1596 |
if push_to_hub:
|
| 1597 |
-
if not re.match(r'^[a-zA-Z0-9_-]+/[a-zA-Z0-9_.-]+$', push_to_hub):
|
| 1598 |
yield (
|
| 1599 |
"**Error:** Invalid Hub repo format. Use `username/model-name`.",
|
| 1600 |
"", gr.update(), gr.update(), gr.update(), gr.update(),
|
|
@@ -1753,7 +1761,10 @@ def obliterate(model_choice: str, method_choice: str, hub_repo: str,
|
|
| 1753 |
vol_label = "all" if prompt_volume == -1 else str(prompt_volume)
|
| 1754 |
log_lines.append(f"Prompt volume: {vol_label} pairs")
|
| 1755 |
if push_to_hub:
|
| 1756 |
-
|
|
|
|
|
|
|
|
|
|
| 1757 |
if quantization:
|
| 1758 |
log_lines.append(f"Quantization: {quantization} (auto-detected for GPU fit)")
|
| 1759 |
log_lines.append("")
|
|
@@ -3498,12 +3509,18 @@ with gr.Blocks(theme=THEME, css=CSS, js=_JS, title="OBLITERATUS", fill_height=Tr
|
|
| 3498 |
)
|
| 3499 |
|
| 3500 |
with gr.Row():
|
| 3501 |
-
|
| 3502 |
-
label="
|
| 3503 |
-
|
| 3504 |
-
info="
|
| 3505 |
"Requires HF_TOKEN env var with write access.",
|
| 3506 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3507 |
hub_warning_md = gr.Markdown("")
|
| 3508 |
|
| 3509 |
# ββ Advanced Settings (auto-populated from method preset) ββββ
|
|
@@ -4155,7 +4172,7 @@ The winner gets auto-pushed to HuggingFace Hub.
|
|
| 4155 |
tourney_hub_org = gr.Textbox(
|
| 4156 |
label="HF Hub Org (optional)",
|
| 4157 |
placeholder="my-org",
|
| 4158 |
-
info="Push winner to hub-org/model-name-
|
| 4159 |
)
|
| 4160 |
with gr.Column(scale=1):
|
| 4161 |
tourney_hub_repo = gr.Textbox(
|
|
@@ -4206,7 +4223,7 @@ The winner gets auto-pushed to HuggingFace Hub.
|
|
| 4206 |
# Resolve display label β HuggingFace model ID
|
| 4207 |
model_id = model_choice.strip()
|
| 4208 |
if model_id in MODELS:
|
| 4209 |
-
model_id = MODELS[model_id]
|
| 4210 |
|
| 4211 |
hub_org_val = hub_org.strip() if hub_org and hub_org.strip() else None
|
| 4212 |
hub_repo_val = hub_repo.strip() if hub_repo and hub_repo.strip() else None
|
|
@@ -4582,7 +4599,7 @@ Built on the shoulders of:
|
|
| 4582 |
# may not fire after generator teardown.
|
| 4583 |
obliterate_btn.click(
|
| 4584 |
fn=obliterate,
|
| 4585 |
-
inputs=[model_dd, method_dd, hub_repo, prompt_vol_dd, dataset_dd,
|
| 4586 |
custom_harmful_tb, custom_harmless_tb] + _adv_controls,
|
| 4587 |
outputs=[status_md, log_box, chat_status, session_model_dd, metrics_md, ab_session_model_dd],
|
| 4588 |
).then(
|
|
|
|
| 1511 |
|
| 1512 |
|
| 1513 |
@spaces.GPU(duration=300)
|
| 1514 |
+
def obliterate(model_choice: str, method_choice: str,
|
| 1515 |
+
hub_auto_push: bool, hub_repo: str,
|
| 1516 |
prompt_volume_choice: str, dataset_source_choice: str,
|
| 1517 |
custom_harmful: str, custom_harmless: str,
|
| 1518 |
# Advanced params (sliders)
|
|
|
|
| 1545 |
model_id = MODELS.get(model_choice, model_choice)
|
| 1546 |
is_preset = model_choice in MODELS
|
| 1547 |
method = METHODS.get(method_choice, "advanced")
|
| 1548 |
+
# Resolve push-to-hub: explicit repo overrides auto-naming
|
| 1549 |
+
_hub_override = hub_repo.strip() if hub_repo and hub_repo.strip() else None
|
| 1550 |
+
if _hub_override:
|
| 1551 |
+
push_to_hub = _hub_override
|
| 1552 |
+
elif hub_auto_push:
|
| 1553 |
+
push_to_hub = "auto" # resolved to {user}/{model}-OBLITERATED at push time
|
| 1554 |
+
else:
|
| 1555 |
+
push_to_hub = None
|
| 1556 |
prompt_volume = PROMPT_VOLUMES.get(prompt_volume_choice, 33)
|
| 1557 |
|
| 1558 |
# Resolve "adaptive" β telemetry-recommended method for this model
|
|
|
|
| 1602 |
|
| 1603 |
# Early validation: Hub repo format + HF_TOKEN
|
| 1604 |
if push_to_hub:
|
| 1605 |
+
if push_to_hub != "auto" and not re.match(r'^[a-zA-Z0-9_-]+/[a-zA-Z0-9_.-]+$', push_to_hub):
|
| 1606 |
yield (
|
| 1607 |
"**Error:** Invalid Hub repo format. Use `username/model-name`.",
|
| 1608 |
"", gr.update(), gr.update(), gr.update(), gr.update(),
|
|
|
|
| 1761 |
vol_label = "all" if prompt_volume == -1 else str(prompt_volume)
|
| 1762 |
log_lines.append(f"Prompt volume: {vol_label} pairs")
|
| 1763 |
if push_to_hub:
|
| 1764 |
+
if push_to_hub == "auto":
|
| 1765 |
+
log_lines.append("Push to Hub: auto ({you}/{model}-OBLITERATED)")
|
| 1766 |
+
else:
|
| 1767 |
+
log_lines.append(f"Push to Hub: {push_to_hub}")
|
| 1768 |
if quantization:
|
| 1769 |
log_lines.append(f"Quantization: {quantization} (auto-detected for GPU fit)")
|
| 1770 |
log_lines.append("")
|
|
|
|
| 3509 |
)
|
| 3510 |
|
| 3511 |
with gr.Row():
|
| 3512 |
+
hub_auto_push = gr.Checkbox(
|
| 3513 |
+
label="Auto-push to Hub",
|
| 3514 |
+
value=False,
|
| 3515 |
+
info="Auto-names your model {you}/{model}-OBLITERATED and pushes to HF Hub. "
|
| 3516 |
"Requires HF_TOKEN env var with write access.",
|
| 3517 |
)
|
| 3518 |
+
hub_repo = gr.Textbox(
|
| 3519 |
+
label="Push to Hub (optional override)",
|
| 3520 |
+
placeholder="auto-filled when checkbox is ticked, or type your own",
|
| 3521 |
+
info="Leave blank with checkbox ticked for auto-naming, "
|
| 3522 |
+
"or enter a custom repo ID (e.g. your-username/my-model).",
|
| 3523 |
+
)
|
| 3524 |
hub_warning_md = gr.Markdown("")
|
| 3525 |
|
| 3526 |
# ββ Advanced Settings (auto-populated from method preset) ββββ
|
|
|
|
| 4172 |
tourney_hub_org = gr.Textbox(
|
| 4173 |
label="HF Hub Org (optional)",
|
| 4174 |
placeholder="my-org",
|
| 4175 |
+
info="Push winner to hub-org/model-name-OBLITERATED",
|
| 4176 |
)
|
| 4177 |
with gr.Column(scale=1):
|
| 4178 |
tourney_hub_repo = gr.Textbox(
|
|
|
|
| 4223 |
# Resolve display label β HuggingFace model ID
|
| 4224 |
model_id = model_choice.strip()
|
| 4225 |
if model_id in MODELS:
|
| 4226 |
+
model_id = MODELS[model_id]
|
| 4227 |
|
| 4228 |
hub_org_val = hub_org.strip() if hub_org and hub_org.strip() else None
|
| 4229 |
hub_repo_val = hub_repo.strip() if hub_repo and hub_repo.strip() else None
|
|
|
|
| 4599 |
# may not fire after generator teardown.
|
| 4600 |
obliterate_btn.click(
|
| 4601 |
fn=obliterate,
|
| 4602 |
+
inputs=[model_dd, method_dd, hub_auto_push, hub_repo, prompt_vol_dd, dataset_dd,
|
| 4603 |
custom_harmful_tb, custom_harmless_tb] + _adv_controls,
|
| 4604 |
outputs=[status_md, log_box, chat_status, session_model_dd, metrics_md, ab_session_model_dd],
|
| 4605 |
).then(
|
obliteratus/abliterate.py
CHANGED
|
@@ -504,6 +504,31 @@ class StageResult:
|
|
| 504 |
details: dict[str, Any] = field(default_factory=dict)
|
| 505 |
|
| 506 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 507 |
# ββ Main pipeline βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 508 |
|
| 509 |
class AbliterationPipeline:
|
|
@@ -5921,11 +5946,17 @@ class AbliterationPipeline:
|
|
| 5921 |
|
| 5922 |
# 5. Optionally push the saved directory to the Hub.
|
| 5923 |
if self.push_to_hub:
|
| 5924 |
-
repo_id = self.push_to_hub
|
| 5925 |
-
self.log(f"Uploading to Hub: {repo_id}")
|
| 5926 |
from huggingface_hub import HfApi
|
| 5927 |
|
| 5928 |
api = HfApi()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5929 |
api.create_repo(repo_id, exist_ok=True)
|
| 5930 |
api.upload_folder(
|
| 5931 |
folder_path=str(self.output_dir),
|
|
|
|
| 504 |
details: dict[str, Any] = field(default_factory=dict)
|
| 505 |
|
| 506 |
|
| 507 |
+
def auto_hub_repo_id(model_name: str, *, api=None) -> str:
|
| 508 |
+
"""Generate a Hub repo ID like ``{hf_user}/{short_model}-OBLITERATED``.
|
| 509 |
+
|
| 510 |
+
Resolves the authenticated HF username via the API, and extracts a
|
| 511 |
+
short model name (e.g. ``meta-llama/Llama-3-8B`` β ``Llama-3-8B``).
|
| 512 |
+
"""
|
| 513 |
+
import re
|
| 514 |
+
|
| 515 |
+
if api is None:
|
| 516 |
+
from huggingface_hub import HfApi
|
| 517 |
+
api = HfApi()
|
| 518 |
+
|
| 519 |
+
# Resolve HF username from token
|
| 520 |
+
user_info = api.whoami()
|
| 521 |
+
username = user_info.get("name") or user_info.get("user", "unknown")
|
| 522 |
+
|
| 523 |
+
# Extract short model name (part after '/')
|
| 524 |
+
short = model_name.split("/")[-1] if "/" in model_name else model_name
|
| 525 |
+
# Sanitize: keep alphanumeric, hyphens, dots
|
| 526 |
+
short = re.sub(r"[^a-zA-Z0-9\-.]", "-", short)
|
| 527 |
+
short = re.sub(r"-+", "-", short).strip("-")
|
| 528 |
+
|
| 529 |
+
return f"{username}/{short}-OBLITERATED"
|
| 530 |
+
|
| 531 |
+
|
| 532 |
# ββ Main pipeline βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 533 |
|
| 534 |
class AbliterationPipeline:
|
|
|
|
| 5946 |
|
| 5947 |
# 5. Optionally push the saved directory to the Hub.
|
| 5948 |
if self.push_to_hub:
|
|
|
|
|
|
|
| 5949 |
from huggingface_hub import HfApi
|
| 5950 |
|
| 5951 |
api = HfApi()
|
| 5952 |
+
|
| 5953 |
+
# Resolve "auto" β {hf_user}/{short_model}-OBLITERATED
|
| 5954 |
+
if self.push_to_hub == "auto":
|
| 5955 |
+
repo_id = auto_hub_repo_id(self.model_name, api=api)
|
| 5956 |
+
self.log(f"Auto-named Hub repo: {repo_id}")
|
| 5957 |
+
else:
|
| 5958 |
+
repo_id = self.push_to_hub
|
| 5959 |
+
self.log(f"Uploading to Hub: {repo_id}")
|
| 5960 |
api.create_repo(repo_id, exist_ok=True)
|
| 5961 |
api.upload_folder(
|
| 5962 |
folder_path=str(self.output_dir),
|
obliteratus/tourney.py
CHANGED
|
@@ -557,7 +557,7 @@ class TourneyRunner:
|
|
| 557 |
if self.hub_repo:
|
| 558 |
repo_id = self.hub_repo
|
| 559 |
else:
|
| 560 |
-
repo_id = f"{self.hub_org}/{short_model}-
|
| 561 |
result.hub_repo = repo_id
|
| 562 |
|
| 563 |
self.log(f"\nPushing winner to Hub: {repo_id}")
|
|
|
|
| 557 |
if self.hub_repo:
|
| 558 |
repo_id = self.hub_repo
|
| 559 |
else:
|
| 560 |
+
repo_id = f"{self.hub_org}/{short_model}-OBLITERATED"
|
| 561 |
result.hub_repo = repo_id
|
| 562 |
|
| 563 |
self.log(f"\nPushing winner to Hub: {repo_id}")
|