sd-scripts icon indicating copy to clipboard operation
sd-scripts copied to clipboard

Error in train_network.py UnicodeEncodeError: 'charmap' codec can't encode characters in position 27-42

Open kulzae opened this issue 1 year ago • 3 comments

im running into this error when starting the training. I have renamed all my files in case it was something with the filenames causing issues and it did not resolve it.

accelerate : Traceback (most recent call last):
At C:\Users\Aaron\sd-scripts\Train.ps1:28 char:1
+ accelerate launch --num_cpu_threads_per_process 8 train_network.py `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Traceback (most recent call last)::String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
  File "C:\Users\Aaron\sd-scripts\train_network.py", line 507, in <module>
    train(args)
  File "C:\Users\Aaron\sd-scripts\train_network.py", line 61, in train
    train_dataset = DreamBoothDataset(args.train_batch_size, args.train_data_dir, args.reg_data_dir,
  File "C:\Users\Aaron\sd-scripts\library\train_util.py", line 797, in __init__
    print("no regularization images / \u6b63\u5247\u5316\u753b\u50cf\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f")
  File "C:\Users\Aaron\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 27-42: character maps to <undefined>
Traceback (most recent call last):
  File "C:\Users\Aaron\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\Aaron\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\Aaron\sd-scripts\venv\Scripts\accelerate.exe\__main__.py", line 7, in <module>
  File "C:\Users\Aaron\sd-scripts\venv\lib\site-packages\accelerate\commands\accelerate_cli.py", line 45, in main
    args.func(args)
  File "C:\Users\Aaron\sd-scripts\venv\lib\site-packages\accelerate\commands\launch.py", line 1104, in launch_command
    simple_launcher(args)
  File "C:\Users\Aaron\sd-scripts\venv\lib\site-packages\accelerate\commands\launch.py", line 567, in simple_launcher
    raise subprocess.CalledProcessError(returncode=process.returncode, cmd=cmd)
subprocess.CalledProcessError: Command '['C:\\Users\\Aaron\\sd-scripts\\venv\\Scripts\\python.exe', 'train_network.py', '--network_module=networks.lora', 
'--pretrained_model_name_or_path=C:\\Users\\Aaron\\sd-scripts\\Model', '--train_data_dir=C:\\Users\\Aaron\\sd-scripts\\Input\\Kulza', 
'--reg_data_dir=C:\\Users\\Aaron\\sd-scripts\\Input\\Reg', '--output_dir=C:\\Users\\Aaron\\sd-scripts\\Output', '--caption_extension=.txt', '--shuffle_caption', 
'--keep_tokens=1\n', '--prior_loss_weight=1', '--resolution=512', '--enable_bucket', '--min_bucket_reso=320', '--max_bucket_reso=960', '--train_batch_size=2', 
'--learning_rate=0.0002', '--unet_lr=0.0002', '--text_encoder_lr=9E-05', '--max_train_epochs=8', '--mixed_precision=fp16', '--save_precision=fp16', 
'--optimizer_type=AdamW8bit', '--xformers', '--save_every_n_epochs=1', '--save_model_as=safetensors', '--clip_skip=2', '--seed=420', '--flip_aug', '--network_dim=160', 
'--network_alpha=128', '--max_token_length=225', '--cache_latents', '--lr_scheduler=cosine_with_restarts', '--noise_offset=0']' returned non-zero exit status 1.

kulzae avatar Feb 25 '23 22:02 kulzae

Same ;( Did you find a solution?

Toxminn avatar Mar 22 '23 20:03 Toxminn

Your script seems to be UTF-16 encoding. Please clone the repo again or save the file in UTF-8 and try again.

kohya-ss avatar Mar 24 '23 12:03 kohya-ss

I fixed it by starting Kohya-ss through the "main" Python File instead of the Windows Batch File. Real simple/silly solution. After running kohya from "main" instead the

UnicodeEncodeError: 'charmap' codec can't encode characters in position 27-42: character maps to error stopped appearing for me and I had no further problems. Hope this helps Screenshot 2024-04-17 014239

Cataleptic avatar Apr 17 '24 05:04 Cataleptic