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

[DOCS] Adding GenAI Use Cases #27062

Conversation

sgolebiewski-intel
Copy link
Contributor

@sgolebiewski-intel sgolebiewski-intel commented Oct 15, 2024

Creating an article with use case scenarios for using OpenVINO GenAI. This PR addresses the following

JIRA ticket: CVS-153319

Co-authored-by: Karol Blaszczak <karol.blaszczak@intel.com>
Comment on lines 59 to 98
#include "openvino/genai/text2image/pipeline.hpp"

#include "imwrite.hpp"

int32_t main(int32_t argc, char* argv[]) {
OPENVINO_ASSERT(argc >= 3 && (argc - 3) % 2 == 0, "Usage: ", argv[0], " <MODEL_DIR> '<PROMPT>' [<LORA_SAFETENSORS> <ALPHA> ...]]");

const std::string models_path = argv[1], prompt = argv[2];
const std::string device = "CPU"; // GPU, NPU can be used as well.

ov::genai::AdapterConfig adapter_config;
// Applying Multiple LoRA adapters simultaneously is supported. Parse them all and the corresponding alphas from cmd parameters:
for(size_t i = 0; i < (argc - 3)/2; ++i) {
ov::genai::Adapter adapter(argv[3 + 2*i]);
float alpha = std::atof(argv[3 + 2*i + 1]);
adapter_config.add(adapter, alpha);
}

// LoRA adapters passed to the constructor will be activated by default in the next generation.
ov::genai::Text2ImagePipeline pipe(models_path, device, ov::genai::adapters(adapter_config));

std::cout << "Generating image with LoRA adapters applied, resulting image will be in lora.bmp\n";
ov::Tensor image = pipe.generate(prompt,
ov::genai::random_generator(std::make_shared<ov::genai::CppStdGenerator>(42)),
ov::genai::width(512),
ov::genai::height(896),
ov::genai::num_inference_steps(20));
imwrite("lora.bmp", image, true);

std::cout << "Generating image without LoRA adapters applied, resulting image will be in baseline.bmp\n";
image = pipe.generate(prompt,
ov::genai::adapters(), // Passing adapters as generation overrides set in the constructor; adapters() means no adapters.
ov::genai::random_generator(std::make_shared<ov::genai::CppStdGenerator>(42)),
ov::genai::width(512),
ov::genai::height(896),
ov::genai::num_inference_steps(20));
imwrite("baseline.bmp", image, true);

return EXIT_SUCCESS;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we prepare less bulky code snippet to be used as on-line illustration? Is there a goal to use exactly the same code as in samples? I think we can make reader life easier with a more distilled code.


.. code-block:: cpp

int main(int argc, char* argv[]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the built-in code from the code sample

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can we reach a decision here? @slyalin I am taking into consideration your comment regarding distilling the code snippets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, we see 2 possible solutions.

  1. We can keep the whole built-in code, while commenting out some lines of code, thus leaving the part on which users can focus.
    image

  2. We keep the distilled code and provide a link to the source example.

image

Please, share your thoughts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an option to embed the sample from a repo? Avoiding copy would be the best solution

Copy link
Contributor

Choose a reason for hiding this comment

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

Or is it called built-in code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there an option to embed the sample from a repo? Avoiding copy would be the best solution

As far as I know, it is impossible to directly embed files outside the scope of openvino/docs directory. We can make reference to such files.

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case having such commented out code is weird to me, so distilled code looks is better. @andrei-kochin will take a look once more.

Would there be some mechanism ensuring the code snippets are kept up to date?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case having such commented out code is weird to me, so distilled code looks is better. @andrei-kochin will take a look once more.

Would there be some mechanism ensuring the code snippets are kept up to date?

For now, I believe, these snippets will be listed under usual maintenance items to keep them up to date.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sgolebiewski-intel I agree to keep only inline comment related to the device. Others are not required and can be removed

@sgolebiewski-intel sgolebiewski-intel added this pull request to the merge queue Oct 24, 2024
Merged via the queue into openvinotoolkit:master with commit 3c0005e Oct 24, 2024
126 checks passed
@sgolebiewski-intel sgolebiewski-intel deleted the genai-examples-for-master branch October 24, 2024 15:03
CuriousPanCake pushed a commit to CuriousPanCake/openvino that referenced this pull request Nov 6, 2024
Creating an article with use case scenarios for using OpenVINO GenAI.
This PR addresses the following

JIRA ticket: CVS-153319

---------

Co-authored-by: Karol Blaszczak <karol.blaszczak@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: docs OpenVINO documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants