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

LCM cpp demo #101

Merged
merged 10 commits into from
Dec 29, 2023
Merged

LCM cpp demo #101

merged 10 commits into from
Dec 29, 2023

Conversation

likholat
Copy link
Contributor

@likholat likholat commented Dec 21, 2023

ToDo:

  • Add Readme
  • Add test
  • IR from optimum

Only static model is supported for now

@likholat likholat marked this pull request as ready for review December 22, 2023 18:20
Copy link
Collaborator

@Wovchena Wovchena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried to run it yet

image_generation/lcm_dreamshaper_v7/cpp/CMakeLists.txt Outdated Show resolved Hide resolved
image_generation/lcm_dreamshaper_v7/cpp/README.md Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with master target branch, but you may want to retarget to releases

image_generation/lcm_dreamshaper_v7/cpp/README.md Outdated Show resolved Hide resolved
image_generation/lcm_dreamshaper_v7/cpp/README.md Outdated Show resolved Hide resolved
image_generation/common/diffusers/src/scheduler_lcm.cpp Outdated Show resolved Hide resolved
image_generation/lcm_dreamshaper_v7/cpp/src/main.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

py scripts\convert_model.py -lcm "SimianLuo/LCM_Dreamshaper_v7" -t FP16 printed

Exception ignored in: <finalize object at 0x1fa1050bd20; dead>
Traceback (most recent call last):
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\weakref.py", line 590, in __call__
    return info.func(*info.args, **(info.kwargs or {}))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\tempfile.py", line 894, in _cleanup
    cls._rmtree(name, ignore_errors=ignore_errors)
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\tempfile.py", line 890, in _rmtree
    _shutil.rmtree(name, onerror=onerror)
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
    return _rmtree_unsafe(path, onerror)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 622, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\tempfile.py", line 881, in onerror
    cls._rmtree(path, ignore_errors=ignore_errors)
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\tempfile.py", line 890, in _rmtree
    _shutil.rmtree(name, onerror=onerror)
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
    return _rmtree_unsafe(path, onerror)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 603, in _rmtree_unsafe
    onerror(os.scandir, path, sys.exc_info())
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 600, in _rmtree_unsafe
    with os.scandir(path) as scandir_it:
         ^^^^^^^^^^^^^^^^
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\Users\\vzlobin\\AppData\\Local\\Temp\\tmp0btk8gby\\text_encoder\\openvino_model.bin'

Although it didn't fail. There's the same issue for stable_diffusion_1_5, but maybe you know what to do about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

py scripts\convert_model.py -lcm "SimianLuo/LCM_Dreamshaper_v7" -t FP16 printed

Exception ignored in: <finalize object at 0x1fa1050bd20; dead>
Traceback (most recent call last):
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\weakref.py", line 590, in __call__
    return info.func(*info.args, **(info.kwargs or {}))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\tempfile.py", line 894, in _cleanup
    cls._rmtree(name, ignore_errors=ignore_errors)
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\tempfile.py", line 890, in _rmtree
    _shutil.rmtree(name, onerror=onerror)
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
    return _rmtree_unsafe(path, onerror)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 617, in _rmtree_unsafe
    _rmtree_unsafe(fullname, onerror)
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 622, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\tempfile.py", line 881, in onerror
    cls._rmtree(path, ignore_errors=ignore_errors)
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\tempfile.py", line 890, in _rmtree
    _shutil.rmtree(name, onerror=onerror)
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 759, in rmtree
    return _rmtree_unsafe(path, onerror)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 603, in _rmtree_unsafe
    onerror(os.scandir, path, sys.exc_info())
  File "C:\Users\vzlobin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 600, in _rmtree_unsafe
    with os.scandir(path) as scandir_it:
         ^^^^^^^^^^^^^^^^
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\Users\\vzlobin\\AppData\\Local\\Temp\\tmp0btk8gby\\text_encoder\\openvino_model.bin'

Although it didn't fail. There's the same issue for stable_diffusion_1_5, but maybe you know what to do about it?

it looks like optimum issue

image_generation/lcm_dreamshaper_v7/cpp/README.md Outdated Show resolved Hide resolved
image_generation/lcm_dreamshaper_v7/cpp/README.md Outdated Show resolved Hide resolved
image_generation/lcm_dreamshaper_v7/cpp/README.md Outdated Show resolved Hide resolved
image_generation/lcm_dreamshaper_v7/cpp/README.md Outdated Show resolved Hide resolved
image_generation/lcm_dreamshaper_v7/cpp/README.md Outdated Show resolved Hide resolved
image_generation/lcm_dreamshaper_v7/cpp/README.md Outdated Show resolved Hide resolved
@likholat likholat force-pushed the lcm_support branch 2 times, most recently from 557f851 to 3756a06 Compare December 28, 2023 15:56
Comment on lines +1 to +2
#include <list>

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <list>

image_generation/lcm_dreamshaper_v7/cpp/README.md Outdated Show resolved Hide resolved
@Wovchena Wovchena merged commit 4116365 into openvinotoolkit:master Dec 29, 2023
2 checks passed
@likholat
Copy link
Contributor Author

@Wovchena @ilya-lavrenov thanks for review :)

model = OVLatentConsistencyModelPipeline.from_pretrained(args.lcm_weights,trust_remote_code=True, export=True, compile=False)
if args.type == "FP16":
model.half()
model.reshape(1, 512, 512, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we don't use FP16? Looks like the model will be saved with dynamic shapes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here: #135


ov::Tensor text_embeddings(ov::element::f32, {1, MAX_LENGTH, HIDDEN_SIZE});

compute_text_embeddings(pos_prompt, ov::Tensor(text_embeddings, {0, 0, 0}, {1, MAX_LENGTH, HIDDEN_SIZE}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we can embed (remove) this lambda since it's called only once


std::vector<float> res_vec(half_dim), emb_cos(half_dim);
std::transform(emb_vec.begin(), emb_vec.end(), res_vec.begin(), [](float x){return std::sin(x);});
std::transform(emb_vec.begin(), emb_vec.end(), emb_cos.begin(), [](float x){return std::cos(x);});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we can remove this multiple std::transform calls with simple for loop, which performs several operations at once

ov::Tensor latent_model_input = randn_tensor(height, width, read_np_latent, seed);

float guidance_scale = 8.0;
ov::Tensor guidance_scale_embedding = get_w_embedding(guidance_scale, 256);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guidance_scale_embedding creation can be moved outside of the num_images loop

* `-s, --seed arg` Number of random seed to generate latent (default: 42)
* `--num arg` Number of image output(default: 1)
* `--height arg` Height of output image (default: 512)
* `--width arg` Width of output image (default: 512)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's stated that Only static model is currently supported for this sample. So, do we need height and width parameters then?

@likholat
Copy link
Contributor Author

likholat commented Jan 9, 2024

#135

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.

3 participants