Skip to content
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

Lora interrogator fixes #392

Merged
merged 2 commits into from
Apr 19, 2023
Merged

Lora interrogator fixes #392

merged 2 commits into from
Apr 19, 2023

Conversation

A2va
Copy link
Contributor

@A2va A2va commented Apr 9, 2023

This fixes some problems in the lora interrogator. However I'm facing an stacktrace error when I run the script, I don't know how to resolve it so I will leave here:

Traceback (most recent call last):
  File "D:\GitHub\sd-scripts\networks\lora_interrogator.py", line 137, in <module>
    interrogate(args)
  File "D:\GitHub\sd-scripts\networks\lora_interrogator.py", line 95, in interrogate
    lora_embs = get_all_embeddings(text_encoder)
  File "D:\GitHub\sd-scripts\networks\lora_interrogator.py", line 76, in get_all_embeddings
    encoder_hidden_states = text_encoder(batch)[0]
  File "D:\compiler\Python\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
  File "D:\compiler\Python\lib\site-packages\transformers\models\clip\modeling_clip.py", line 816, in forward
    return self.text_model(
  File "D:\compiler\Python\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\compiler\Python\lib\site-packages\transformers\models\clip\modeling_clip.py", line 725, in forward
    encoder_outputs = self.encoder(
  File "D:\compiler\Python\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\compiler\Python\lib\site-packages\transformers\models\clip\modeling_clip.py", line 654, in forward
    layer_outputs = encoder_layer(
  File "D:\compiler\Python\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\compiler\Python\lib\site-packages\transformers\models\clip\modeling_clip.py", line 383, in forward
    hidden_states, attn_weights = self.self_attn(
  File "D:\compiler\Python\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\compiler\Python\lib\site-packages\transformers\models\clip\modeling_clip.py", line 272, in forward
    query_states = self.q_proj(hidden_states) * self.scale
  File "D:\compiler\Python\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\GitHub\sd-scripts\networks\lora.py", line 105, in forward
    return self.org_forward(x) + self.lora_up(self.lora_down(x)) * self.multiplier * self.scale
  File "D:\compiler\Python\lib\site-packages\torch\nn\modules\module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\compiler\Python\lib\site-packages\torch\nn\modules\linear.py", line 114, in forward
    return F.linear(input, self.weight, self.bias)
RuntimeError: expected scalar type Half but found Float

@A2va A2va changed the title Fixes Lora interrogator fixes Apr 10, 2023
@kohya-ss
Copy link
Owner

Thank you for this! I didn't tested after the last update of the utils. I will check the error.

@heyalexchoi
Copy link

I get an error running these changes. looks like train_util.load_target_model expects a argparse.Namespace with pretrained_model_name_or_path attribute.

File "/home/alexchoi/sd-scripts/./networks/lora_interrogator.py", line 22, in interrogate
    text_encoder, vae, unet, _ = train_util.load_target_model(args, args.sd_model, DEVICE)
  File "/home/alexchoi/anaconda3/envs/sd-scripts/lib/python3.10/site-packages/library/train_util.py", line 2784, in load_target_model
    name_or_path = args.pretrained_model_name_or_path
AttributeError: 'Namespace' object has no attribute 'pretrained_model_name_or_path'

@heyalexchoi
Copy link

this fixes issues for me

#423

@A2va
Copy link
Contributor Author

A2va commented Apr 17, 2023

Your fix in the new PR is already included in mine.

@kohya-ss kohya-ss changed the base branch from main to dev April 19, 2023 11:20
@kohya-ss kohya-ss merged commit f770cd9 into kohya-ss:dev Apr 19, 2023
@kohya-ss
Copy link
Owner

I've merged! I restored --sd_model argument for the backward compatibility, and fixed some additional bugs.

@A2va
Copy link
Contributor Author

A2va commented Apr 19, 2023

Thanks ! What was the fix with the stacktrace ?

@kohya-ss
Copy link
Owner

It seems to be required to set dtype explicitly. However, I'm not sure why it work before 😅

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.

None yet

3 participants