Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Implement LoRA patching via the Loader #211

Merged
merged 14 commits into from
May 14, 2023
Merged

Implement LoRA patching via the Loader #211

merged 14 commits into from
May 14, 2023

Conversation

LLukas22
Copy link
Contributor

This pull request adds the ability to apply a LoRA adapter while loading the model. The adapter can be defined via the optional lora_adapter field in ModelParameters.

The patches are then lazily applied while the tensors are loaded via the MmapCompatibleLoader.

This currently produces garbled outputs. Probably because the weights aren't copied correctly from the patched_tensor to the base_tensor.

Currently the weights are moved by setting the tensor data directly, this probably doesn't work as i expected it to.

unsafe {
    tensor.set_data(target_tensor.data());
}

To use a LoRA adapter via the cli simply add a --lora-path flag.

Example: llama infer --model-path "path\to\model" --lora-path "path\to\adapter" -p "The meaning of life is"

@LLukas22
Copy link
Contributor Author

Alright the output is now correct (at least not gibberish anymore). I just moved the memory regions correctly and its working now.

@LLukas22 LLukas22 marked this pull request as ready for review May 11, 2023 16:20
@philpax
Copy link
Collaborator

philpax commented May 12, 2023

Will look at soon! Can you mention what you tested with, and make Clippy happy?

@LLukas22
Copy link
Contributor Author

Sure i used this Alpaca adapter and this LLama base model.

@LLukas22
Copy link
Contributor Author

Maybe the vicuna-chat should be removed from the examples 🤔

@philpax
Copy link
Collaborator

philpax commented May 12, 2023

That'd be a question for @danforbes 🤔 What would be your reasoning for removing it?

@LLukas22
Copy link
Contributor Author

Its fine, just had a brain-lag. Thought i was another inference example but its an actual chat implementation.😅

@philpax philpax merged commit f523cbf into rustformers:main May 14, 2023
@LLukas22 LLukas22 deleted the feat/lora branch May 16, 2023 13:28
@hhamud hhamud mentioned this pull request Aug 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants