kohya-ss / sd-scripts

Apache License 2.0
5.12k stars 853 forks source link

TypeError: 'type' object is not subscriptable #38

Closed zakinp closed 1 year ago

zakinp commented 1 year ago

An error called "TypeError: 'type' object is not subscriptable" occurs when using 'train_network.py' to finetune model.

The whole message is:

import network module: networks.lora Traceback (most recent call last): File "/root/autodl-tmp/sd-scripts/train_network.py", line 1455, in train(args) File "/root/autodl-tmp/sd-scripts/train_network.py", line 1092, in train network = network_module.create_network(1.0, args.network_dim, vae, text_encoder, unet, **net_kwargs) File "/root/autodl-tmp/sd-scripts/networks/lora.py", line 50, in create_network network = LoRANetwork(text_encoder, unet, multiplier=multiplier, lora_dim=network_dim) File "/root/autodl-tmp/sd-scripts/networks/lora.py", line 66, in init def create_modules(prefix, root_module: torch.nn.Module, target_replace_modules) -> list[LoRAModule]: TypeError: 'type' object is not subscriptable Traceback (most recent call last): File "/root/miniconda3/bin/accelerate", line 8, in sys.exit(main()) File "/root/miniconda3/lib/python3.8/site-packages/accelerate/commands/accelerate_cli.py", line 45, in main args.func(args) File "/root/miniconda3/lib/python3.8/site-packages/accelerate/commands/launch.py", line 1104, in launch_command simple_launcher(args) File "/root/miniconda3/lib/python3.8/site-packages/accelerate/commands/launch.py", line 567, in simple_launcher raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd) subprocess.CalledProcessError: Command '['/root/miniconda3/bin/python', '/root/autodl-tmp/sd-scripts/train_network.py', '--pretrained_model_name_or_path=/root/autodl-tmp/finalmodel.ckpt', '--in_json=/root/autodl-tmp/liangxing-lat.json', '--shuffle_caption', '--keep_tokens=1', '--train_data_dir=/root/autodl-tmp/liangxing', '--dataset_repeats=10', '--output_dir=/root/autodl-tmp/liangxing-lora-test', '--save_precision=float', '--save_model_as=ckpt', '--save_every_n_epochs=1', '--save_state', '--color_aug', '--flip_aug', '--resolution=640,640', '--train_batch_size=4', '--max_token_length=225', '--learning_rate=1e-4', '--prior_loss_weight=1.0', '--seed=2998', '--unet_lr=1e-4', '--text_encoder_lr=1e-6', '--max_train_steps=8955', '--gradient_checkpointing', '--gradient_accumulation_steps=2', '--mixed_precision=no', '--clip_skip=2', '--logging_dir=logs', '--lr_scheduler=polynomial', '--lr_warmup_steps=450', '--network_module=networks.lora']' returned non-zero exit status 1.

It seems to be related to the 'networks.lora' module. How to fix this ? Btw, the '--network_module' cannot be set as 'None', otherwise an another error will appear:

import network module: None Traceback (most recent call last): File "/root/autodl-tmp/sd-scripts/train_network.py", line 1455, in train(args) File "/root/autodl-tmp/sd-scripts/train_network.py", line 1084, in train network_module = importlib.import_module(args.network_module) File "/root/miniconda3/lib/python3.8/importlib/init.py", line 118, in import_module if name.startswith('.'): AttributeError: 'NoneType' object has no attribute 'startswith' Traceback (most recent call last): File "/root/miniconda3/bin/accelerate", line 8, in sys.exit(main()) File "/root/miniconda3/lib/python3.8/site-packages/accelerate/commands/accelerate_cli.py", line 45, in main args.func(args) File "/root/miniconda3/lib/python3.8/site-packages/accelerate/commands/launch.py", line 1104, in launch_command simple_launcher(args) File "/root/miniconda3/lib/python3.8/site-packages/accelerate/commands/launch.py", line 567, in simple_launcher raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd) subprocess.CalledProcessError: Command '['/root/miniconda3/bin/python', '/root/autodl-tmp/sd-scripts/train_network.py', '--pretrained_model_name_or_path=/root/autodl-tmp/finalmodel.ckpt', '--in_json=/root/autodl-tmp/liangxing-lat.json', '--shuffle_caption', '--keep_tokens=1', '--train_data_dir=/root/autodl-tmp/liangxing', '--dataset_repeats=10', '--output_dir=/root/autodl-tmp/liangxing-lora-test', '--save_precision=float', '--save_model_as=ckpt', '--save_every_n_epochs=1', '--save_state', '--color_aug', '--flip_aug', '--resolution=640,640', '--train_batch_size=4', '--max_token_length=225', '--learning_rate=1e-4', '--prior_loss_weight=1.0', '--seed=2998', '--unet_lr=1e-4', '--text_encoder_lr=1e-6', '--max_train_steps=8955', '--gradient_checkpointing', '--gradient_accumulation_steps=2', '--mixed_precision=no', '--clip_skip=2', '--logging_dir=logs', '--lr_scheduler=polynomial', '--lr_warmup_steps=450']' returned non-zero exit status 1.

kohya-ss commented 1 year ago

The error seems to be related to type hints feature of Python.

->list[LoRAModule]:

This notation seems to be supported from Python 3.9. This repo is tested on Python 3.10, but you seem to use Python 3.8. Please update Python to 3.10.x.

If it is difficult, please remove ->list[LoRAModule]. However, another error might occur, so I recommend to use Python 3.10.

zakinp commented 1 year ago

The error seems to be related to type hints feature of Python.

->list[LoRAModule]:

This notation seems to be supported from Python 3.9. This repo is tested on Python 3.10, but you seem to use Python 3.8. Please update Python to 3.10.x.

If it is difficult, please remove ->list[LoRAModule]. However, another error might occur, so I recommend to use Python 3.10.

thanks, I'll try it later.

zakinp commented 1 year ago

I found that this error is caused by python version, which should be updated to 3.10.x. This issue can be closed.