-
Notifications
You must be signed in to change notification settings - Fork 165
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 #83 from Narsil/recipe_for_other_models
Adding recipe for other models (non llama, non vicuna).
- Loading branch information
Showing
5 changed files
with
181 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import typer | ||
import json | ||
from transformers import Conversation | ||
from typing_extensions import Annotated | ||
import httpx | ||
import tqdm | ||
import asyncio | ||
|
||
app = typer.Typer() | ||
|
||
|
||
client = httpx.AsyncClient(timeout=None) | ||
|
||
async def run(conv: Conversation): | ||
payload = {"model":"tgi", "messages": conv.messages} | ||
response = await client.post(url, json=payload) | ||
content = response.json() | ||
message = content["choices"][0]["message"] | ||
message.pop("name") | ||
conv.add_message(message) | ||
|
||
|
||
|
||
|
||
def fix_source(source): | ||
if source and source[0]["from"] == "gpt": | ||
# Skip if GPT is first to talk | ||
source = source[1:] | ||
new_source = [] | ||
for item in source: | ||
role = "assistant" if item["from"] == "gpt" else "user" | ||
content = item["value"] | ||
new_source.append({"role": role, "content": content}) | ||
return new_source | ||
|
||
|
||
async def recreate_conversation(conversation, sem): | ||
async with sem: | ||
conv = Conversation() | ||
try: | ||
for message in conversation[::2]: | ||
assert message["role"] == "user" | ||
conv.add_message(message) | ||
await run(conv) | ||
except Exception: | ||
pass | ||
return conv.messages | ||
|
||
@app.command() | ||
def main( | ||
*, | ||
input_filename: Annotated[str, typer.Option("--input-filename")], | ||
output_filename: Annotated[str, typer.Option("--output-filename")], | ||
url: Annotated[str, typer.Option("--url")] = "http://localhost:8080/v1/chat/completions", | ||
concurrency: Annotated[int, typer.Option("--concurrency")] = 64 | ||
): | ||
sem = asyncio.Semaphore(concurrency) | ||
async def _main(): | ||
with open(input_filename, "r") as f: | ||
input_data = json.loads(f.read()) | ||
conversations = [fix_source(source["conversations"]) for source in input_data] | ||
|
||
futures = [] | ||
for conversation in conversations: | ||
future = recreate_conversation(conversation, sem) | ||
futures.append(future) | ||
|
||
recreated_conversations = await tqdm.asyncio.tqdm.gather(*futures) | ||
|
||
with open(output_filename, "w") as f: | ||
json.dump(recreated_conversations, f, indent=4) | ||
asyncio.run(_main()) | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
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,24 @@ | ||
{ | ||
"bf16": { | ||
"enabled": "auto" | ||
}, | ||
|
||
"zero_optimization": { | ||
"stage": 3, | ||
"overlap_comm": true, | ||
"contiguous_gradients": true, | ||
"sub_group_size": 1e9, | ||
"reduce_bucket_size": "auto", | ||
"stage3_prefetch_bucket_size": "auto", | ||
"stage3_param_persistence_threshold": "auto", | ||
"stage3_max_live_parameters": 1e9, | ||
"stage3_max_reuse_distance": 1e9, | ||
"stage3_gather_16bit_weights_on_model_save": true | ||
}, | ||
|
||
"gradient_accumulation_steps": "auto", | ||
"steps_per_print": 2000, | ||
"train_batch_size": "auto", | ||
"train_micro_batch_size_per_gpu": "auto", | ||
"wall_clock_breakdown": false | ||
} |
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.