Skip to content

Fix AttributeError in train_t2i_adapter_sdxl checkpoint resume#13521

Open
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Ricardo-M-L:fix-t2i-adapter-sdxl-control-type-bug
Open

Fix AttributeError in train_t2i_adapter_sdxl checkpoint resume#13521
Ricardo-M-L wants to merge 1 commit intohuggingface:mainfrom
Ricardo-M-L:fix-t2i-adapter-sdxl-control-type-bug

Conversation

@Ricardo-M-L
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a latent AttributeError in examples/t2i_adapter/train_t2i_adapter_sdxl.py that breaks --resume_from_checkpoint.

The accelerate load_model_hook references args.control_type, which is never declared as a CLI argument in this script:

def load_model_hook(models, input_dir):
    while len(models) > 0:
        model = models.pop()

        # load diffusers style into model
        load_model = T2IAdapter.from_pretrained(os.path.join(input_dir, "t2iadapter"))

        if args.control_type != "style":
            model.register_to_config(**load_model.config)

        model.load_state_dict(load_model.state_dict())
        del load_model

So any resume (accelerator.load_state(...) triggered by --resume_from_checkpoint) crashes with:

AttributeError: 'Namespace' object has no attribute 'control_type'

The args.control_type != "style" gate looks like a copy-paste leftover from a controlnet variant that distinguished style adapters. This T2IAdapter training script has no such distinction, and the analogous hook in examples/controlnet/train_controlnet_sdxl.py calls register_to_config unconditionally. Dropping the broken gate aligns with that script and makes resume work.

Fix

-                if args.control_type != "style":
-                    model.register_to_config(**load_model.config)
+                model.register_to_config(**load_model.config)

Before submitting

Who can review?

@sayakpaul

`load_model_hook` gates `model.register_to_config(**load_model.config)`
behind `args.control_type != "style"`, but `--control_type` is not
defined as an argparse argument anywhere in this script, so resuming
from a checkpoint (any `--resume_from_checkpoint ...`) crashes with:

    AttributeError: 'Namespace' object has no attribute 'control_type'

The gate appears to be a leftover from a controlnet variant that
differentiated style adapters. T2IAdapter training here has no such
distinction, and the analogous `train_controlnet_sdxl.py` hook always
calls `register_to_config` unconditionally. Drop the broken gate so
checkpoint resume works.
@github-actions github-actions Bot added examples size/S PR with diff < 50 LOC labels Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

examples size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant