harbor run -t openthoughts/tasktrove-mix-h4-binary-easy-mix-h4-binary-easy-0697harbor download openthoughts/tasktrove-mix-h4-binary-easy-mix-h4-binary-easy-0697solution file
import asyncio
import websockets
import json
from sentencepiece import SentencePieceProcessor
from model import ExLlama, ExLlamaCache, ExLlamaConfig
from lora import ExLlamaLora
from tokenizer import ExLlamaTokenizer
from generator import ExLlamaGenerator
import argparse
import torch
import sys
import os
import glob
import model_init
# Initialized from command line args by init()
model: ExLlama
cache: ExLlamaCache
config: ExLlamaConfig
generator: ExLlamaGenerator
tokenizer: ExLlamaTokenizer
max_cached_strings = 100
tokenizer_cache = {}
prompt_ids: torch.tensor
stop_strings: list
stop_tokens: list
held_text: str
max_stop_string: int
remaining_tokens: int
full_prompt: str
utilized_prompt: str
built_response: str
def cached_tokenize(text: str):
global model, cache, config, generator, tokenizer
global max_cached_strings, tokenizer_cache
if text in tokenizer_cache:
return tokenizer_cache[text]
while len(tokenizer_cache) >= max_cached_strings:
del tokenizer_cache[next(iter(tokenizer_cache))] # Always removes oldest entry as of Python 3.7
new_enc = tokenizer.encode(text)
tokenizer_cache[text] = new_enc
return new_enc
def begin_stream(prompt: str, stop_conditions: list, max_new_tokens: int, gen_settings: ExLlamaGenerator.Settings):
global model, cache, config, generator, tokenizer
global stop_strings, stop_tokens, prompt_ids, held_text, max_stop_string, remaining_tokens
global full_prompt, utilized_prompt, built_response
# Tokenize prompt and limit length to allow prompt and (max) new tokens within max sequence length
max_input_tokens = model.config.max_seq_len - max_new_tokens
input_ids = cached_tokenize(prompt)
input_ids = input_ids[:, -max_input_tokens:]
prompt_ids = input_ids
full_prompt = prompt
utilized_prompt = tokenizer.
Complete the code above, taking into account the cross-file context provided. Your solution must work correctly with the related files in the project.
Place your complete solution in /app/solution.py