mirror of
https://github.com/p-e-w/heretic.git
synced 2026-09-25 21:41:26 -07:00
fix: improve formatting of reproducibility README
This commit is contained in:
@@ -367,6 +367,11 @@ class Settings(BaseSettings):
|
|||||||
description="Benchmarks to offer to the user for evaluating abliterated models.",
|
description="Benchmarks to offer to the user for evaluating abliterated models.",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
max_shard_size: int | str = Field(
|
||||||
|
default="5GB",
|
||||||
|
description="Maximum size for individual safetensors files generated when exporting a model.",
|
||||||
|
)
|
||||||
|
|
||||||
refusal_markers: list[str] = Field(
|
refusal_markers: list[str] = Field(
|
||||||
default=[
|
default=[
|
||||||
"sorry",
|
"sorry",
|
||||||
|
|||||||
+10
-2
@@ -759,11 +759,17 @@ def run():
|
|||||||
|
|
||||||
if strategy == "adapter":
|
if strategy == "adapter":
|
||||||
print("Saving LoRA adapter...")
|
print("Saving LoRA adapter...")
|
||||||
model.model.save_pretrained(save_directory)
|
model.model.save_pretrained(
|
||||||
|
save_directory,
|
||||||
|
max_shard_size=settings.max_shard_size,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print("Saving merged model...")
|
print("Saving merged model...")
|
||||||
merged_model = model.get_merged_model()
|
merged_model = model.get_merged_model()
|
||||||
merged_model.save_pretrained(save_directory)
|
merged_model.save_pretrained(
|
||||||
|
save_directory,
|
||||||
|
max_shard_size=settings.max_shard_size,
|
||||||
|
)
|
||||||
del merged_model
|
del merged_model
|
||||||
empty_cache()
|
empty_cache()
|
||||||
model.tokenizer.save_pretrained(save_directory)
|
model.tokenizer.save_pretrained(save_directory)
|
||||||
@@ -857,6 +863,7 @@ def run():
|
|||||||
model.model.push_to_hub(
|
model.model.push_to_hub(
|
||||||
repo_id,
|
repo_id,
|
||||||
private=private,
|
private=private,
|
||||||
|
max_shard_size=settings.max_shard_size,
|
||||||
token=token,
|
token=token,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -865,6 +872,7 @@ def run():
|
|||||||
merged_model.push_to_hub(
|
merged_model.push_to_hub(
|
||||||
repo_id,
|
repo_id,
|
||||||
private=private,
|
private=private,
|
||||||
|
max_shard_size=settings.max_shard_size,
|
||||||
token=token,
|
token=token,
|
||||||
)
|
)
|
||||||
del merged_model
|
del merged_model
|
||||||
|
|||||||
+53
-38
@@ -275,21 +275,28 @@ def get_readme_intro(
|
|||||||
trial: Trial,
|
trial: Trial,
|
||||||
contains_reproducibility_information: bool,
|
contains_reproducibility_information: bool,
|
||||||
) -> str:
|
) -> str:
|
||||||
if Path(settings.model).exists():
|
if is_hf_path(settings.model):
|
||||||
|
model_link = f"[{settings.model}](https://huggingface.co/{settings.model})"
|
||||||
|
else:
|
||||||
# Hide the path, which may contain private information.
|
# Hide the path, which may contain private information.
|
||||||
model_link = "a model"
|
model_link = "a model"
|
||||||
else:
|
|
||||||
model_link = f"[{settings.model}](https://huggingface.co/{settings.model})"
|
|
||||||
|
|
||||||
version_info = get_heretic_version_info()
|
version_info = get_heretic_version_info()
|
||||||
|
|
||||||
|
if contains_reproducibility_information:
|
||||||
|
reproducibility_instructions = """
|
||||||
|
> [!TIP]
|
||||||
|
> **This model is reproducible!**
|
||||||
|
>
|
||||||
|
> See the [README](reproduce/README.md) in the `reproduce` directory for more information.
|
||||||
|
"""
|
||||||
|
else:
|
||||||
|
reproducibility_instructions = ""
|
||||||
|
|
||||||
return f"""# This is a decensored version of {
|
return f"""# This is a decensored version of {
|
||||||
model_link
|
model_link
|
||||||
}, made using [Heretic](https://github.com/p-e-w/heretic) v{version_info.version}
|
}, made using [Heretic](https://github.com/p-e-w/heretic) v{version_info.version}
|
||||||
{
|
{reproducibility_instructions}
|
||||||
f"{chr(10)}**This model is reproducible!** See the [`reproduce`](reproduce) directory and its [README](reproduce/README.md) for more information.{chr(10)}"
|
|
||||||
if contains_reproducibility_information
|
|
||||||
else ""
|
|
||||||
}
|
|
||||||
## Abliteration parameters
|
## Abliteration parameters
|
||||||
|
|
||||||
| Parameter | Value |
|
| Parameter | Value |
|
||||||
@@ -355,7 +362,7 @@ def format_hf_link(
|
|||||||
link = f"[{name}]({base_url})"
|
link = f"[{name}]({base_url})"
|
||||||
if commit:
|
if commit:
|
||||||
commit_url = f"{base_url}/commit/{commit}"
|
commit_url = f"{base_url}/commit/{commit}"
|
||||||
link += f" (Commit: [{commit[:7]}]({commit_url}))"
|
link += f" (Commit: [`{commit[:7]}`]({commit_url}))"
|
||||||
|
|
||||||
return link
|
return link
|
||||||
|
|
||||||
@@ -378,9 +385,12 @@ def generate_reproduce_readme(
|
|||||||
if len(device_names) > 1:
|
if len(device_names) > 1:
|
||||||
heterogeneous_warning = """
|
heterogeneous_warning = """
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> **Heterogeneous GPUs!**
|
> **Heterogeneous GPUs**
|
||||||
> This model was generated using multiple non-identical GPUs. When operations are distributed across different GPUs (e.g. via `device_map='auto'`),
|
>
|
||||||
> non-deterministic behavior can occur. **Reproducibility ***cannot*** be guaranteed in this environment.**
|
> This model was generated using multiple non-identical GPUs. When operations are distributed across different GPUs
|
||||||
|
> (e.g. via `device_map='auto'`), non-deterministic behavior can occur.
|
||||||
|
>
|
||||||
|
> Reproducibility *cannot* be guaranteed in this environment.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cpu = get_cpu_info_dict()
|
cpu = get_cpu_info_dict()
|
||||||
@@ -391,37 +401,35 @@ def generate_reproduce_readme(
|
|||||||
accelerator_report = "**No GPU or other accelerator detected.**"
|
accelerator_report = "**No GPU or other accelerator detected.**"
|
||||||
else:
|
else:
|
||||||
devices = accelerators["devices"]
|
devices = accelerators["devices"]
|
||||||
total_vram = sum(d.get("vram_gb", 0) for d in devices)
|
total_vram = sum(device.get("vram_gb", 0) for device in devices)
|
||||||
vram_suffix = (
|
vram_suffix = f" ({total_vram:.2f} GB total VRAM)" if total_vram > 0 else ""
|
||||||
f" (`{total_vram:.2f} GB` total VRAM)" if total_vram > 0 else ""
|
|
||||||
)
|
|
||||||
accelerator_lines = [
|
accelerator_lines = [
|
||||||
f"- **{accelerators['type']}:** Detected `{len(devices)}` device(s){vram_suffix}"
|
f"- **{accelerators['type']}:** Detected {len(devices)} device(s){vram_suffix}"
|
||||||
]
|
]
|
||||||
|
|
||||||
if accelerators.get("api_name") and accelerators.get("api_version"):
|
if accelerators.get("api_name") and accelerators.get("api_version"):
|
||||||
accelerator_lines.append(
|
accelerator_lines.append(
|
||||||
f" - **{accelerators['api_name']}:** `{accelerators['api_version']}`"
|
f" - **{accelerators['api_name']}:** {accelerators['api_version']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
if accelerators.get("driver_version"):
|
if accelerators.get("driver_version"):
|
||||||
accelerator_lines.append(
|
accelerator_lines.append(
|
||||||
f" - **Driver Version:** `{accelerators['driver_version']}`"
|
f" - **Driver Version:** {accelerators['driver_version']}"
|
||||||
)
|
)
|
||||||
|
|
||||||
accelerator_lines.append("- **Devices:**")
|
accelerator_lines.append("- **Devices:**")
|
||||||
for i, dev in enumerate(devices):
|
for i, device in enumerate(devices):
|
||||||
vram = f" (`{dev['vram_gb']:.2f} GB`)" if dev.get("vram_gb") else ""
|
vram = f" ({device['vram_gb']:.2f} GB)" if device.get("vram_gb") else ""
|
||||||
accelerator_lines.append(
|
accelerator_lines.append(
|
||||||
f" - **{accelerators['type']} {i}:** `{dev['name']}`{vram}"
|
f" - **{accelerators['type']} {i}:** {device['name']}{vram}"
|
||||||
)
|
)
|
||||||
accelerator_report = "\n".join(accelerator_lines)
|
accelerator_report = "\n".join(accelerator_lines)
|
||||||
|
|
||||||
system_report = f"""## System
|
system_report = f"""## System
|
||||||
|
|
||||||
- **Python:** `{python_env["version"]}` (`{python_env["implementation"]}`, `{python_env["compiler"]}`) [`{python_env["environment"]}`]
|
- **Python:** {python_env["version"]} ({python_env["implementation"]}, {python_env["compiler"]}) [{python_env["environment"]}]
|
||||||
- **Operating system:** `{platform.platform()}` (`{platform.machine()}`)
|
- **Operating system:** {platform.platform()} ({platform.machine()})
|
||||||
- **CPU:** `{cpu["brand"] or "Unknown CPU"}`
|
- **CPU:** {cpu["brand"] or "Unknown"}
|
||||||
|
|
||||||
### Accelerators
|
### Accelerators
|
||||||
|
|
||||||
@@ -440,26 +448,32 @@ def generate_reproduce_readme(
|
|||||||
origin_warning = ""
|
origin_warning = ""
|
||||||
if not version_info.is_standard_pypi:
|
if not version_info.is_standard_pypi:
|
||||||
if version_info.origin and version_info.origin.startswith("Git"):
|
if version_info.origin and version_info.origin.startswith("Git"):
|
||||||
repo_info = version_info.origin.split("Git (")[1].strip(")")
|
repo_info = version_info.origin.split("Git (")[1].rstrip(")")
|
||||||
origin_warning = f"""
|
origin_warning = f"""
|
||||||
> [!NOTE]
|
> [!IMPORTANT]
|
||||||
> **Git installation!**
|
> **Git installation**
|
||||||
> This system installed Heretic from a Git repository: `{repo_info}`.
|
>
|
||||||
|
> This system installed Heretic from a Git repository: {repo_info}
|
||||||
|
>
|
||||||
> To reproduce the model, you must install Heretic from this exact repository and commit.
|
> To reproduce the model, you must install Heretic from this exact repository and commit.
|
||||||
"""
|
"""
|
||||||
elif version_info.origin == "Local":
|
elif version_info.origin == "Local":
|
||||||
origin_warning = """
|
origin_warning = """
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> **Local code!**
|
> **Local code**
|
||||||
|
>
|
||||||
> This system installed Heretic from a local directory or wheel. Uncommitted or experimental code may have been executed.
|
> This system installed Heretic from a local directory or wheel. Uncommitted or experimental code may have been executed.
|
||||||
> **Reproducibility ***cannot*** be guaranteed in this environment.**
|
>
|
||||||
|
> Reproducibility *cannot* be guaranteed in this environment.
|
||||||
"""
|
"""
|
||||||
else:
|
else:
|
||||||
origin_warning = """
|
origin_warning = """
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
> **Non-standard installation!**
|
> **Non-standard installation**
|
||||||
|
>
|
||||||
> This system installed Heretic from an unknown non-standard source.
|
> This system installed Heretic from an unknown non-standard source.
|
||||||
> **Reproducibility ***cannot*** be guaranteed in this environment.**
|
>
|
||||||
|
> Reproducibility *cannot* be guaranteed in this environment.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pytorch_version = torch.__version__
|
pytorch_version = torch.__version__
|
||||||
@@ -488,14 +502,14 @@ This directory contains the necessary information and assets to reproduce the re
|
|||||||
|
|
||||||
## Selected trial
|
## Selected trial
|
||||||
|
|
||||||
- **Trial number:** `{trial.user_attrs["index"]}`
|
- **Trial number:** {trial.user_attrs["index"]}
|
||||||
- **KL divergence:** `{trial.user_attrs["kl_divergence"]:.6f}`
|
- **KL divergence:** {trial.user_attrs["kl_divergence"]:.6f}
|
||||||
- **Refusals:** `{trial.user_attrs["refusals"]}/{trial.user_attrs["n_bad_prompts"]}`
|
- **Refusals:** {trial.user_attrs["refusals"]}/{trial.user_attrs["n_bad_prompts"]}
|
||||||
|
|
||||||
{system_report}## Environment
|
{system_report}## Environment
|
||||||
|
|
||||||
- **Heretic:** `v{version_info.version}`{f" (Origin: `{version_info.origin}`)" if version_info.origin else ""}
|
- **Heretic:** v{version_info.version}{f" (Origin: {version_info.origin})" if version_info.origin else ""}
|
||||||
- **PyTorch:** `{pytorch_version}`
|
- **PyTorch:** {pytorch_version}
|
||||||
- **Other dependencies:** See [`requirements.txt`](requirements.txt).
|
- **Other dependencies:** See [`requirements.txt`](requirements.txt).
|
||||||
|
|
||||||
## Contents of this directory
|
## Contents of this directory
|
||||||
@@ -518,6 +532,7 @@ This directory contains the necessary information and assets to reproduce the re
|
|||||||
|
|
||||||
> [!TIP]
|
> [!TIP]
|
||||||
> To use the included Optuna study journal `{checkpoint_filename}`, place it in the checkpoints directory (usually `checkpoints/`) before running Heretic.
|
> To use the included Optuna study journal `{checkpoint_filename}`, place it in the checkpoints directory (usually `checkpoints/`) before running Heretic.
|
||||||
|
>
|
||||||
> This allows you to export other models from the Pareto front, or to run additional trials without having to re-run the stored trials.
|
> This allows you to export other models from the Pareto front, or to run additional trials without having to re-run the stored trials.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user