-
Notifications
You must be signed in to change notification settings - Fork 2.3k
feat: Write README.md for LoRA adapter as well #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anrp
wants to merge
2
commits into
p-e-w:master
Choose a base branch
from
anrp:anrp/loradetails2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+158
−107
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # SPDX-License-Identifier: AGPL-3.0-or-later | ||
| # Copyright (C) 2025-2026 Philipp Emanuel Weidmann <pew@worldwidemann.com> + contributors | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import huggingface_hub | ||
| from huggingface_hub import ModelCard, ModelCardData | ||
| from optuna import Trial | ||
|
|
||
| from .config import RowNormalization, Settings | ||
| from .system import ( | ||
| get_heretic_version_info, | ||
| ) | ||
| from .utils import get_trial_parameters, is_hf_path | ||
|
|
||
|
|
||
| def get_readme_intro( | ||
| settings: Settings, | ||
| trial: Trial, | ||
| contains_reproducibility_information: bool, | ||
| is_lora: bool, | ||
| ) -> str: | ||
| 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. | ||
| model_link = "a model" | ||
|
|
||
| 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 {"adapter" if is_lora else "version"} of { | ||
| model_link | ||
| }, made using [Heretic](https://github.com/p-e-w/heretic) v{version_info.version} | ||
| {reproducibility_instructions} | ||
| ## Abliteration parameters | ||
|
|
||
| | Parameter | Value | | ||
| | :-------- | :---: | | ||
| { | ||
| chr(10).join( | ||
| [ | ||
| f"| **{name}** | {value} |" | ||
| for name, value in get_trial_parameters(trial).items() | ||
| ] | ||
| ) | ||
| } | ||
|
|
||
| ## Performance | ||
|
|
||
| | Metric | This model | Original model ({model_link}) | | ||
| | :----- | :--------: | :---------------------------: | | ||
| | **KL divergence** | {trial.user_attrs["kl_divergence"]:.4f} | 0 *(by definition)* | | ||
| | **Refusals** | {trial.user_attrs["refusals"]}/{trial.user_attrs["n_bad_prompts"]} | { | ||
| trial.user_attrs["base_refusals"] | ||
| }/{trial.user_attrs["n_bad_prompts"]} | | ||
|
|
||
| ----- | ||
|
|
||
| """ | ||
|
|
||
|
|
||
| def get_model_card( | ||
| settings: Settings, | ||
| trial: Trial, | ||
| reproducibility_information: str, | ||
| is_lora: bool, | ||
| ) -> ModelCard | None: | ||
| # If the model path exists locally and includes the | ||
| # card, use it directly. If the model path doesn't | ||
| # exist locally, it can be assumed to be a model | ||
| # hosted on the Hugging Face Hub, in which case | ||
| # we can retrieve the model card. | ||
| if is_hf_path(settings.model): | ||
| card = ModelCard.load(settings.model) | ||
| else: | ||
| card_path = Path(settings.model) / huggingface_hub.constants.REPOCARD_NAME | ||
| if card_path.exists(): | ||
| card = ModelCard.load(card_path) | ||
| else: | ||
| card = None | ||
|
|
||
| if card is not None: | ||
| if card.data is None: | ||
| card.data = ModelCardData() | ||
| if card.data.tags is None: | ||
| card.data.tags = [] | ||
| card.data.tags.append("heretic") | ||
| card.data.tags.append("uncensored") | ||
| card.data.tags.append("decensored") | ||
| card.data.tags.append("abliterated") | ||
| if ( | ||
| settings.orthogonalize_direction | ||
| and settings.row_normalization == RowNormalization.FULL | ||
| ): | ||
| card.data.tags.append("mpoa") | ||
| if reproducibility_information != "none": | ||
| card.data.tags.append("reproducible") | ||
|
|
||
| if is_hf_path(settings.model): | ||
| card.data.base_model = settings.model | ||
| card.data.base_model_relation = "adapter" if is_lora else "finetuned" | ||
|
|
||
| card.text = ( | ||
| get_readme_intro( | ||
| settings, | ||
| trial, | ||
| reproducibility_information != "none", | ||
| is_lora, | ||
| ) | ||
| + card.text | ||
| ) | ||
|
|
||
| return card | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.