-
Notifications
You must be signed in to change notification settings - Fork 197
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
[WIP] LoRA for FLUX #1353
Draft
slyalin
wants to merge
4
commits into
openvinotoolkit:master
Choose a base branch
from
slyalin:lora_flux
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+43
−3
Draft
[WIP] LoRA for FLUX #1353
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ed2d70a
FLUX dev and lite support
likholat 3e12130
LoRA for FLUX. Works with vanilla tensor naming only. Requires extend…
slyalin 668dd5e
Merge remote-tracking branch 'origin/master' into lora_flux
slyalin 1a9e834
Merge branch 'master' into lora_flux
slyalin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,15 @@ | |
|
||
#include "json_utils.hpp" | ||
#include "utils.hpp" | ||
#include "lora_helper.hpp" | ||
|
||
namespace { | ||
void get_input_names(std::vector<std::string>& input_names, const std::vector<ov::Output<const ov::Node>>& inputs_info) { | ||
for (const auto& port : inputs_info) { | ||
input_names.push_back(port.get_any_name()); | ||
} | ||
} | ||
} | ||
|
||
namespace ov { | ||
namespace genai { | ||
|
@@ -108,7 +117,16 @@ FluxTransformer2DModel& FluxTransformer2DModel::reshape(int batch_size, | |
|
||
FluxTransformer2DModel& FluxTransformer2DModel::compile(const std::string& device, const ov::AnyMap& properties) { | ||
OPENVINO_ASSERT(m_model, "Model has been already compiled. Cannot re-compile already compiled model"); | ||
ov::CompiledModel compiled_model = utils::singleton_core().compile_model(m_model, device, properties); | ||
std::optional<AdapterConfig> adapters; | ||
ov::CompiledModel compiled_model; | ||
if (auto filtered_properties = extract_adapters_from_properties(properties, &adapters)) { | ||
adapters->set_tensor_name_prefix(adapters->get_tensor_name_prefix().value_or("transformer")); | ||
m_adapter_controller = AdapterController(m_model, *adapters, device); | ||
compiled_model = utils::singleton_core().compile_model(m_model, device, *filtered_properties); | ||
} else { | ||
compiled_model = utils::singleton_core().compile_model(m_model, device, properties); | ||
} | ||
get_input_names(m_config.m_model_input_names, compiled_model.inputs()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. obsolete code |
||
m_request = compiled_model.create_infer_request(); | ||
// release the original model | ||
m_model.reset(); | ||
|
@@ -121,6 +139,13 @@ void FluxTransformer2DModel::set_hidden_states(const std::string& tensor_name, o | |
m_request.set_tensor(tensor_name, encoder_hidden_states); | ||
} | ||
|
||
void FluxTransformer2DModel::set_adapters(const std::optional<AdapterConfig>& adapters) { | ||
OPENVINO_ASSERT(m_request, "Transformer model must be compiled first"); | ||
if(adapters) { | ||
m_adapter_controller.apply(m_request, *adapters); | ||
} | ||
} | ||
|
||
ov::Tensor FluxTransformer2DModel::infer(const ov::Tensor latent_model_input, const ov::Tensor timestep) { | ||
OPENVINO_ASSERT(m_request, "Transformer model must be compiled first. Cannot infer non-compiled model"); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, add LoRA adapters here:
openvino.genai/src/cpp/src/image_generation/flux_pipeline.hpp
Lines 313 to 315 in aef1591