NVlabs / Sana

SANA: Efficient High-Resolution Image Synthesis with Linear Diffusion Transformer
https://nvlabs.github.io/Sana
Other
744 stars 26 forks source link

Failing on colab colab_kernel_launcher.py: error: unrecognized arguments #25

Closed Vargol closed 6 hours ago

Vargol commented 15 hours ago

Hi, trying to run this on Colab as may main I computer is MacOS, but I'm getting issues with the example code in the README.

The error I get is...

colab_kernel_launcher.py: error: unrecognized arguments: -f /root/.local/share/jupyter/runtime/kernel-44d5aa92-13f8-4c86-a46e-c6a472635a6b.json
An exception has occurred, use %tb to see the full traceback.

%tb gives...

---------------------------------------------------------------------------
SystemExit                                Traceback (most recent call last)
[<ipython-input-7-4a593ceb7314>](https://v60rlxggde-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20241120-060119_RC00_698329754#) in <cell line: 1>()
----> 1 sana = SanaPipeline("/content/Sana/configs/sana_config/1024ms/Sana_1600M_img1024.yaml")
      2 

5 frames
[/content/Sana/app/sana_pipeline.py](https://v60rlxggde-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20241120-060119_RC00_698329754#) in __init__(self, config)
     78     ):
     79         super().__init__()
---> 80         config = pyrallis.parse(config_class=SanaInference, config_path=config)
     81         self.args = self.config = config
     82 

[/usr/local/lib/python3.10/dist-packages/pyrallis/argparsing.py](https://v60rlxggde-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20241120-060119_RC00_698329754#) in parse(config_class, config_path, args)
    146           args: Optional[Sequence[str]] = None) -> T:
    147     parser = ArgumentParser(config_class=config_class, config_path=config_path)
--> 148     return parser.parse_args(args)
    149 
    150 

[/usr/local/lib/python3.10/dist-packages/pyrallis/argparsing.py](https://v60rlxggde-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20241120-060119_RC00_698329754#) in parse_args(self, args, namespace)
     80 
     81     def parse_args(self, args=None, namespace=None) -> T:
---> 82         return super().parse_args(args, namespace)
     83 
     84     def parse_known_args(

[/usr/lib/python3.10/argparse.py](https://v60rlxggde-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20241120-060119_RC00_698329754#) in parse_args(self, args, namespace)
   1846         if argv:
   1847             msg = _('unrecognized arguments: %s')
-> 1848             self.error(msg % ' '.join(argv))
   1849         return args
   1850 

[/usr/lib/python3.10/argparse.py](https://v60rlxggde-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20241120-060119_RC00_698329754#) in error(self, message)
   2604         self.print_usage(_sys.stderr)
   2605         args = {'prog': self.prog, 'message': message}
-> 2606         self.exit(2, _('%(prog)s: error: %(message)s\n') % args)

[/usr/lib/python3.10/argparse.py](https://v60rlxggde-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20241120-060119_RC00_698329754#) in exit(self, status, message)
   2591         if message:
   2592             self._print_message(message, _sys.stderr)
-> 2593         _sys.exit(status)
   2594 
   2595     def error(self, message):

SystemExit: 2

Any idea what might be the issue ?

lawrence-cj commented 14 hours ago

run command?

Vargol commented 14 hours ago

https://colab.research.google.com/drive/1HSXXSv1WRsV0flaedvi5WOpZLvAK6n8r?usp=sharing

%%bash
git clone https://github.com/NVlabs/Sana.git
cd Sana
pip install -e .
import sys
import os

sys.path.insert(0, os.path.abspath('Sana'))

import torch
from app.sana_pipeline import SanaPipeline
from torchvision.utils import save_image

device = torch.device("cuda")
generator = torch.Generator(device=device).manual_seed(42)
sana = SanaPipeline("/content/Sana/configs/sana_config/1024ms/Sana_1600M_img1024.yaml")

^^^^ fails here.

lawrence-cj commented 14 hours ago

Try this one, and let's see if it will work.

import pyrallis
from app.sana_pipeline import SanaInference

config = pyrallis.parse(config_class=SanaInference, config_path="/content/Sana/configs/sana_config/1024ms/Sana_1600M_img1024.yaml")
Vargol commented 13 hours ago

Same error by the looks of it

colab_kernel_launcher.py: error: unrecognized arguments: -f /root/.local/share/jupyter/runtime/kernel-44d5aa92-13f8-4c86-a46e-c6a472635a6b.json
An exception has occurred, use %tb to see the full traceback.
import sys
import os

sys.path.insert(0, os.path.abspath('Sana'))

import pyrallis
from app.sana_pipeline import SanaInference

config = pyrallis.parse(config_class=SanaInference, config_path="/content/Sana/configs/sana_config/1024ms/Sana_1600M_img1024.yaml")
lawrence-cj commented 11 hours ago

Then, I suggest you to try if your machine can run with pyrallis. Seems it's something related to this package.

make a new train.py file with:

from dataclasses import dataclass
import pyrallis

@dataclass
class TrainConfig:
    """ Training config for Machine Learning """
    workers: int = 8 # The number of workers for training
    exp_name: str = 'default_exp' # The experiment name

def main():
    cfg = pyrallis.parse(config_class=TrainConfig)
    print(f'Training {cfg.exp_name} with {cfg.workers} workers...')

main()

make a new train.yaml file with:

workers: 4
exp_name: "test"
$ python train.py --config_path=train.yaml
Training my_first_exp with 42 workers...
Vargol commented 10 hours ago

that worked,

Training default_exp with 8 workers...

could this be something like pyrasllis doesn't play well with notebooks ?

Vargol commented 9 hours ago

okay running the inference script as a file gets me further, as it now downloads the models and looks like its starting to do something but doesn't seems to generate anything and outputs a ^C at the end...

! python run_sana.py

 2024-11-22 13:37:22.655597: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:485] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2024-11-22 13:37:22.938755: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:8454] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2024-11-22 13:37:23.017131: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1452] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-11-22 13:37:23.500011: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2024-11-22 13:37:25.688638: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
2024-11-22 21:37:33 - [Sana] - INFO - Sampler flow_dpm-solver, flow_shift: 3.0
2024-11-22 21:37:33 - [Sana] - INFO - Inference with torch.float16, PAG guidance layer: [8]
[DC-AE] Loading model from mit-han-lab/dc-ae-f32c32-sana-1.0
Loading checkpoint shards: 100% 2/2 [00:01<00:00,  1.52it/s]
2024-11-22 21:38:28 - [Sana] - WARNING - use pe: False, position embed interpolation: 1.0, base size: 32
2024-11-22 21:38:28 - [Sana] - WARNING - attention type: linear; ffn type: glumbconv; autocast linear attn: False
^C
odusseys commented 8 hours ago

This fixes it in SanaPipeline:

 # config = pyrallis.parse(config_class=SanaInference, config_path=config)
config = pyrallis.load(SanaInference, open(config, "r"))
lawrence-cj commented 6 hours ago

^C means Ctrl-C, try to re-run the code.

Vargol commented 6 hours ago

I had with the same results, including the printing the ^C to the terminal,. Now I can run it it directly from the notebook , it seems that running as a python script was 'hiding' the colab running out of system RAM, I'd guess that it running as a separate process to the notebook allowed a break to be sent to the processes rather than the hard restart running it as a notebook seems to require.

werruww commented 4 hours ago

config = pyrallis.load(SanaInference, open(config, "r")) SanaPipeline

import torch from app.sana_pipeline import SanaPipeline from torchvision.utils import save_image

device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") generator = torch.Generator(device=device).manual_seed(42)

sana = SanaPipeline("/content/Sana/configs/sana_config/1024ms/Sana_1600M_img1024.yaml") sana.from_pretrained("hf://Efficient-Large-Model/Sana_1600M_1024px/checkpoints/Sana_1600M_1024px.pth") prompt = 'a cyberpunk cat with a neon sign that says "Sana"'

image = sana( prompt=prompt, height=128, width=128, guidance_scale=5.0, pag_guidance_scale=2.0, num_inference_steps=18, generator=generator, ) save_image(image, 'output/sana.png', nrow=1, normalize=True, value_range=(-1, 1))

Your session crashed after using all available RAM.

werruww commented 4 hours ago

colab t4

werruww commented 4 hours ago

import os import sys sys.path.insert(0, os.path.abspath('Sana'))

from huggingface_hub import login from google.colab import userdata

login(token=userdata.get('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'))

import torch from app.sana_pipeline import SanaPipeline from torchvision.utils import save_image

device = torch.device("cuda") generator = torch.Generator(device=device).manual_seed(42)

sana = SanaPipeline("/content/Sana/configs/sana_config/1024ms/Sana_1600M_img1024.yaml") sana.from_pretrained("hf://Efficient-Large-Model/Sana_1600M_1024px/checkpoints/Sana_1600M_1024px.pth") prompt = 'a cyberpunk cat with a neon sign that says "Sana"'

image = sana( prompt=prompt, height=1024, width=1024, guidance_scale=5.0, pag_guidance_scale=2.0, num_inference_steps=18, generator=generator, ) save_image(image, 'output/sana.png', nrow=1, normalize=True, value_range=(-1, 1))

2024-11-23 03:10:55 - [Sana] - INFO - Sampler flow_dpm-solver, flow_shift: 3.0 2024-11-23 03:10:55 - [Sana] - INFO - Inference with torch.float16, PAG guidance layer: [8] [DC-AE] Loading model from mit-han-lab/dc-ae-f32c32-sana-1.0 Loading checkpoint shards: 100%  2/2 [00:01<00:00,  1.35it/s] 2024-11-23 03:12:04 - [Sana] - WARNING - use pe: False, position embed interpolation: 1.0, base size: 32 2024-11-23 03:12:04 - [Sana] - WARNING - attention type: linear; ffn type: glumbconv; autocast linear attn: False

Your session crashed after using all available RAM. View runtime logs Skip

colab t4

werruww commented 4 hours ago

I had with the same results, including the printing the ^C to the terminal,. Now I can run it it directly from the notebook , it seems that running as a python script was 'hiding' the colab running out of system RAM, I'd guess that it running as a separate process to the notebook allowed a break to be sent to the processes rather than the hard restart running it as a notebook seems to require.

how???

code???????

werruww commented 4 hours ago

!python /content/Sana/scripts/inference.py

[1] 25s !python /content/Sana/scripts/inference.py 2024-11-22 19:16:59.870052: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 AVX512F FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. Couldn't find the field 'data' in the dict with keys [] Couldn't find the field 'model' in the dict with keys [] Couldn't find the field 'vae' in the dict with keys [] Couldn't find the field 'text_encoder' in the dict with keys [] Couldn't find the field 'scheduler' in the dict with keys [] Couldn't find the field 'train' in the dict with keys [] Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/pyrallis/parsers/decoding.py", line 86, in decode_dataclass instance = cls(**init_args) # type: ignore TypeError: SanaInference.init() missing 6 required positional arguments: 'data', 'model', 'vae', 'text_encoder', 'scheduler', and 'train'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/content/Sana/scripts/inference.py", line 264, in config = args = pyrallis.parse(config_class=SanaInference, config_path=args.config) File "/usr/local/lib/python3.10/dist-packages/pyrallis/argparsing.py", line 148, in parse return parser.parse_args(args) File "/usr/local/lib/python3.10/dist-packages/pyrallis/argparsing.py", line 82, in parse_args return super().parse_args(args, namespace) File "/usr/lib/python3.10/argparse.py", line 1845, in parse_args args, argv = self.parse_known_args(args, namespace) File "/usr/local/lib/python3.10/dist-packages/pyrallis/argparsing.py", line 107, in parse_known_args parsed_args = self._postprocessing(parsed_args) File "/usr/local/lib/python3.10/dist-packages/pyrallis/argparsing.py", line 140, in _postprocessing cfg = decoding.decode(self.config_class, deflat_d) File "/usr/local/lib/python3.10/dist-packages/pyrallis/parsers/registry_utils.py", line 74, in wrapper return base_func(*args, **kw) File "/usr/local/lib/python3.10/dist-packages/pyrallis/parsers/decoding.py", line 34, in decode return get_decoding_fn(cls)(raw_value) File "/usr/local/lib/python3.10/dist-packages/pyrallis/parsers/decoding.py", line 88, in decode_dataclass raise ParsingError( pyrallis.utils.ParsingError: Couldn't instantiate class <class 'main.SanaInference'> using the given arguments. Underlying error: SanaInference.init() missing 6 required positional arguments: 'data', 'model', 'vae', 'text_encoder', 'scheduler', and 'train'

Vargol commented 4 hours ago

I had with the same results, including the printing the ^C to the terminal,. Now I can run it it directly from the notebook , it seems that running as a python script was 'hiding' the colab running out of system RAM, I'd guess that it running as a separate process to the notebook allowed a break to be sent to the processes rather than the hard restart running it as a notebook seems to require.

how???

code???????

The code is in the notebook I shared earlier, running the code in python I just copied the inference code to a python file, run_sana.py, and created a cell with ! python run_sana.py instead of the cell with the inference code.

Just to be clear it still probably ran out of memory, I just got the Ctrl-C termination instead of the whole colab restarting.

werruww commented 3 hours ago

a.pdf