Skip to content

FIX Call super().__post_init__() in CPTConfig and RandLoraConfig#3365

Merged
BenjaminBossan merged 3 commits into
huggingface:mainfrom
DaoyuanLi2816:fix/config-post-init-super
Jun 30, 2026
Merged

FIX Call super().__post_init__() in CPTConfig and RandLoraConfig#3365
BenjaminBossan merged 3 commits into
huggingface:mainfrom
DaoyuanLi2816:fix/config-post-init-super

Conversation

@DaoyuanLi2816

Copy link
Copy Markdown
Contributor

What does this PR do?

CPTConfig and RandLoraConfig override __post_init__ but do not call super().__post_init__(), so PeftConfig.__post_init__ never runs for them. That base method:

  • auto-fills peft_version (if self.peft_version is None: self.peft_version = self._get_peft_version()), and
  • validates task_type.

As a result, CPTConfig(...).peft_version and RandLoraConfig(...).peft_version are left as None, so the saved adapter_config.json for CPT / RandLoRA adapters does not record the PEFT version that every other adapter type records. The base task_type validation is also skipped.

Of the tuner configs that override __post_init__, all but these two call super().__post_init__(). This PR adds the call (first, matching the convention) so CPT and RandLoRA behave the same.

How it was verified

Before:

  • CPTConfig(task_type="CAUSAL_LM").peft_versionNone
  • RandLoraConfig().peft_versionNone

After:

  • both → e.g. '0.19.2.dev0@UNKNOWN', and the value round-trips through save_pretrained / from_pretrained.
  • The configs' existing __post_init__ logic is unaffected (CPT still sets is_prompt_learning, num_virtual_tokens, …; RandLoRA still sets peft_type and the target_modules set).
  • tests/test_cpt.py and tests/test_randlora.py pass (15 passed).
  • ruff check passes on both files.

Note: #3227 also edits randlora/config.py (the save_projection field default), on different lines — no overlap with this change.

AI assistance

AI assistance was used to prepare this change. I reviewed every changed line, verified the behavior as described above, and take responsibility for the patch.

CPTConfig and RandLoraConfig override __post_init__ without calling
super().__post_init__(), so PeftConfig.__post_init__ never runs for them.
As a result the peft_version field is left as None (instead of being
auto-filled) and the task_type validation in the base class is skipped.
Every other tuner config that overrides __post_init__ calls super();
add the call (first, matching the convention) so these two behave the
same and record peft_version in their saved adapter_config.json.

@BenjaminBossan BenjaminBossan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this omission.

I checked why our tests didn't catch this and found that ALL_CONFIG_CLASSES in tests/tst_config.py doesn't include those two (there might be others that are missing). Could you please add them to the test matrix?

Follow-up to adding the missing configs to ALL_CONFIG_CLASSES:
- CPTConfig requires task_type=CAUSAL_LM to construct and only supports that
  task type, so pin it in mandatory_kwargs and skip it in the generic
  valid/invalid task_type tests (it's still covered by the round-trip tests,
  which is what would have caught the original __post_init__ omission).
- OFTConfig's from_pretrained back-compat guard fires before the generic load
  path, so skip it in the four from_pretrained-based tests.
All other matrix tests now exercise both configs.
@DaoyuanLi2816

Copy link
Copy Markdown
Contributor Author

Thanks! Added them. Diffing ALL_CONFIG_CLASSES against all public PeftConfig subclasses turned up six missing: CPTConfig and RandLoraConfig, plus DeloraConfig, OFTConfig, PveraConfig, WaveFTConfig. All six are in the matrix now.

Two needed a little handling so the generic tests stay green:

  • CPTConfig only supports task_type=CAUSAL_LM (enforced in its __post_init__), so it's pinned in mandatory_kwargs and skipped in test_valid_task_type / test_invalid_task_type. It's still exercised by the round-trip tests (test_methods / test_save_pretrained / test_to_dict / pickle / copy / ...), which is what would have caught the original __post_init__ omission.
  • OFTConfig's from_pretrained has a backwards-compatibility guard that raises before the generic load path, so it's skipped in the four from_pretrained-based tests.

Locally: tests/test_config.py → 1137 passed, 12 skipped; ruff clean.

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@BenjaminBossan BenjaminBossan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking care of syncing the config tests. The PR LGTM.

@BenjaminBossan BenjaminBossan merged commit 853a994 into huggingface:main Jun 30, 2026
10 checks passed
@DaoyuanLi2816 DaoyuanLi2816 deleted the fix/config-post-init-super branch July 1, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants