-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from EricLBuehler/lora_swapping
Implement dynamic LoRA swapping
- Loading branch information
Showing
51 changed files
with
1,820 additions
and
353 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from mistralrs import Runner, Which, ChatCompletionRequest | ||
|
||
runner = Runner( | ||
which=Which.LoraGGUF( | ||
tok_model_id=None, # Automatically determine from ordering file | ||
quantized_model_id="TheBloke/zephyr-7B-beta-GGUF", | ||
quantized_filename="zephyr-7b-beta.Q4_0.gguf", | ||
tokenizer_json=None, | ||
repeat_last_n=64, | ||
xlora_model_id="lamm-mit/x-lora", | ||
order="orderings/xlora-paper-ordering.json", | ||
) | ||
) | ||
|
||
res = runner.send_chat_completion_request( | ||
ChatCompletionRequest( | ||
model="mistral", | ||
messages=[ | ||
{"role": "user", "content": "Tell me a story about the Rust type system."} | ||
], | ||
max_tokens=256, | ||
presence_penalty=1.0, | ||
top_p=0.1, | ||
temperature=0.5, | ||
adapters=["adapter_4"], | ||
) | ||
) | ||
print(res.choices[0].message.content) | ||
print(res.usage) |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from mistralrs import Runner, Which, ChatCompletionRequest | ||
|
||
runner = Runner( | ||
which=Which.LoraGGUF( | ||
tok_model_id=None, # Automatically determine from ordering file | ||
quantized_model_id="TheBloke/zephyr-7B-beta-GGUF", | ||
quantized_filename="zephyr-7b-beta.Q4_0.gguf", | ||
tokenizer_json=None, | ||
repeat_last_n=64, | ||
xlora_model_id="lamm-mit/x-lora", | ||
order="orderings/xlora-paper-ordering.json", | ||
) | ||
) | ||
|
||
# Example: Make adapter_3 the active adapter | ||
runner.activate_adapters(["adapter_3"]) | ||
|
||
res = runner.send_chat_completion_request( | ||
ChatCompletionRequest( | ||
model="mistral", | ||
messages=[ | ||
{"role": "user", "content": "Tell me a story about the Rust type system."} | ||
], | ||
max_tokens=256, | ||
presence_penalty=1.0, | ||
top_p=0.1, | ||
temperature=0.5, | ||
) | ||
) | ||
print(res.choices[0].message.content) | ||
print(res.usage) |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import openai | ||
import httpx | ||
import textwrap, json | ||
|
||
|
||
def log_response(response: httpx.Response): | ||
request = response.request | ||
print(f"Request: {request.method} {request.url}") | ||
print(" Headers:") | ||
for key, value in request.headers.items(): | ||
if key.lower() == "authorization": | ||
value = "[...]" | ||
if key.lower() == "cookie": | ||
value = value.split("=")[0] + "=..." | ||
print(f" {key}: {value}") | ||
print(" Body:") | ||
try: | ||
request_body = json.loads(request.content) | ||
print(textwrap.indent(json.dumps(request_body, indent=2), " ")) | ||
except json.JSONDecodeError: | ||
print(textwrap.indent(request.content.decode(), " ")) | ||
print(f"Response: status_code={response.status_code}") | ||
print(" Headers:") | ||
for key, value in response.headers.items(): | ||
if key.lower() == "set-cookie": | ||
value = value.split("=")[0] + "=..." | ||
print(f" {key}: {value}") | ||
|
||
|
||
openai.api_key = "EMPTY" | ||
openai.base_url = "http://localhost:1234/v1/" | ||
|
||
# Enable this to log requests and responses | ||
# openai.http_client = httpx.Client( | ||
# event_hooks={"request": [print], "response": [log_response]} | ||
# ) | ||
|
||
messages = [] | ||
prompt = input("Enter system prompt >>> ") | ||
if len(prompt) > 0: | ||
messages.append({"role": "system", "content": prompt}) | ||
|
||
|
||
while True: | ||
prompt = input(">>> ") | ||
adapter = input("Active adapter >>> ") | ||
messages.append({"role": "user", "content": prompt}) | ||
completion = openai.chat.completions.create( | ||
model="mistral", | ||
messages=messages, | ||
max_tokens=256, | ||
frequency_penalty=1.0, | ||
top_p=0.1, | ||
temperature=0, | ||
extra_body={"adapters": [adapter]}, | ||
) | ||
resp = completion.choices[0].message.content | ||
print(resp) | ||
messages.append({"role": "assistant", "content": resp}) |
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.