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

Clean up VLMPipeline #68

Closed
wants to merge 46 commits into from
Closed

Conversation

Wovchena
Copy link
Owner

@Wovchena Wovchena commented Oct 7, 2024

Address comments in openvinotoolkit#912

);

/// @brief Default destructor.
~VLMPipeline();

/// @brief Generate a response given a prompt and any number of
/// uint8 RGB images.
/// uint8 RGB images with [HWC] layout.

Choose a reason for hiding this comment

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

if I pass NHWC, what will happen?

Copy link
Owner Author

Choose a reason for hiding this comment

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

1HWC is actually expected. Should I enable both?

Choose a reason for hiding this comment

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

I suppose yes, maybe in PR with multiple images you can add support of NHWC ? where ov::Tensor represents multiple images and N > 1

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done in 7441a18. @popovaan, please, add tests for [NHWC] ([1HWC], [2HWC]) and [HWC] image layouts.

@Wovchena Wovchena mentioned this pull request Oct 8, 2024
AlexKoff88 and others added 3 commits October 8, 2024 08:34
Use the latest Optimum from GitHub:
https://github.com/huggingface/optimum.git

Some example to try:
```sh
# Export FP16 model
 optimum-cli export openvino -m SimianLuo/LCM_Dreamshaper_v7 --weight-format fp16 sd-lcm-fp16
# Export INT8 WOQ model
 optimum-cli export openvino -m SimianLuo/LCM_Dreamshaper_v7 --weight-format int8 sd-lcm-int8
# Collect the references
wwb --base-model sd-lcm-fp16 --gt-data lcm_test/sd_xl.json --model-type sd-lcm
# Compute the metric
wwb --target-model sd-lcm-int8 --gt-data lcm_test/sd_xl.json --model-type sd-lcm
```

In addition you can compare vs. SD LCM quantized in a Hybrid
quantization mode as follows:
```python
import time
import datasets
import matplotlib.pyplot as plt
import numpy as np
import transformers
from pathlib import Path
from openvino.runtime import Core
from optimum.intel import OVConfig, OVQuantizer, OVStableDiffusionPipeline, OVWeightQuantizationConfig, OVLatentConsistencyModelPipeline
from optimum.intel.openvino.configuration import OVQuantizationMethod

transformers.logging.set_verbosity_error()
datasets.logging.set_verbosity_error()

MODEL_ID = "SimianLuo/LCM_Dreamshaper_v7"
DATASET_NAME = "jxie/coco_captions"

base_model_path = Path(f"models/{MODEL_ID}")
fp32_model_path = base_model_path.with_name(base_model_path.name + "_FP32")
int8_model_path = base_model_path.with_name("sd-lcm-int8")

dataset = datasets.load_dataset(DATASET_NAME, split="train", streaming=True).shuffle(seed=42)
print(next(iter(dataset)))

def preprocess_fn(example):
    return {"prompt": example["caption"]}

NUM_SAMPLES = 200
dataset = dataset.take(NUM_SAMPLES)
calibration_dataset = dataset.map(lambda x: preprocess_fn(x), remove_columns=dataset.column_names)

int8_pipe = OVLatentConsistencyModelPipeline.from_pretrained(model_id=MODEL_ID, export=True)
quantization_config = OVWeightQuantizationConfig(bits=8, num_samples=NUM_SAMPLES, quant_method=OVQuantizationMethod.HYBRID)
quantizer = OVQuantizer(int8_pipe)
quantizer.quantize(
    ov_config=OVConfig(quantization_config=quantization_config),
    calibration_dataset=calibration_dataset,
    save_directory=int8_model_path
)
```

And use compute the metric the same way:
```sh
wwb --target-model sd-lcm-int8 --gt-data lcm_test/sd_xl.json --model-type sd-lcm
```
ilya-lavrenov and others added 22 commits October 9, 2024 10:21
- Added VLM bindings.
- Added Python VLM chat sample.
- Added initialization of performance metrics with zeros.
Tickets: CVS-153174, CVS-153173, CVS-153626

PR to miniCPM-V-2_6 branch:
#62

---------

Co-authored-by: wenyi5608 <[email protected]>
Co-authored-by: Yang,Su <[email protected]>
Co-authored-by: Wovchena <[email protected]>
Co-authored-by: Yaroslav Tarkan <[email protected]>
Co-authored-by: Alina Kladieva <[email protected]>
Co-authored-by: Pavel Esir <[email protected]>
Co-authored-by: Pavel Esir <[email protected]>
Co-authored-by: Artur Paniukov <[email protected]>
Co-authored-by: Ekaterina Aidova <[email protected]>
Co-authored-by: Ilya Lavrenov <[email protected]>
Co-authored-by: Mikhail Ryzhov <[email protected]>
TODO:
- [ ] Remove `ov::Core` from constructors.
- [ ] Hide files and API.

---------

Co-authored-by: wenyi5608 <[email protected]>
Co-authored-by: Yang,Su <[email protected]>
Co-authored-by: Yaroslav Tarkan <[email protected]>
Co-authored-by: Alina Kladieva <[email protected]>
Co-authored-by: Pavel Esir <[email protected]>
Co-authored-by: Pavel Esir <[email protected]>
Co-authored-by: Artur Paniukov <[email protected]>
Co-authored-by: Ekaterina Aidova <[email protected]>
Co-authored-by: Ilya Lavrenov <[email protected]>
Co-authored-by: Mikhail Ryzhov <[email protected]>
@ilya-lavrenov
Copy link

Can be closed

@Wovchena Wovchena closed this Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.