O(n^m) to O(n) for finding no target names #2372
Open
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.
The code snippet finds modules that are not targeted by the LoRA adaptor.
Previous implementation is a double for-loop along the modules in the model and lora targets, and has a
O(n*m)
runtime, wheren
can be up to a 1000 andm
can be up to 500 depending on the LoRA. The logic is meant to find model modules that don't contain a suffix (starting with a'.'
or the beginning of the word) found in LoRA targets.Instead of a double for loop, we could split module names by
'.'
to find all potential suffixes, and check if any of them are contained in the LoRA targets, which have been turned into a lookup table. Module names are split into less than 10 suffixes, so it is effectively an O(n) operationThis change reduces the latency of
load_lora_weights()
by around 0.6 seconds on an Azure A100 machine, for a 300MB Flux adaptor (kishlaykumar1995/blinky-flux-lora-32). When the lorastate_dict
is loaded on the GPU already,load_lora_weights()
used to take around 1.1 secs, so it achieves a 50% reduction in latency of applying LoRA