import torchfrom transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfigfrom peft import PeftModel base_model_id = "Qwen/Qwen3.5-2B"adapter_id = "Novasaki/Qwen3.5-2B-GrugSpeech-Q8" # 1. Load Tokenizertokenizer = AutoTokenizer.from_pretrained(adapter_id) # 2. Load Base Model in 8-bitbnb_config = BitsAndBytesConfig(load_in_8bit=True)base_model = AutoModelForCausalLM.from_pretrained( base_model_id, quantization_config=bnb_config, device_map="auto") # 3. Attach LoRA Adaptermodel = PeftModel.from_pretrained(base_model, adapter_id)model.eval() # 4. Optimize Verbose Speech into Grug Speechsystem_prompt = ( "You are a Grug Speech Optimizer. Convert the verbose speech or reasoning into grug speech—an ultra-terse, " "token-compressed internal reasoning style (GPT-5.6 grug brain). " "Rules: Strip all conversational fluff, keep 100% of facts, numbers, logic steps, and conclusions.") verbose_input = """In order to optimize our distributed web crawler, we should replace our synchronous blocking HTTP client with an asynchronous event loop using uvloop and aiohttp. Currently, each crawling thread blocks waiting on socket I/O, which limits our throughput to roughly 50 requests per second and exhausts our system thread pool. By switching to an async connection pool with a maximum concurrency limit of 1000 open sockets and HTTP keep-alive enabled, we can achieve over 2,500 requests per second while reducing CPU utilization from 85% down to 25%.""" messages = [ {"role": "system", "content": system_prompt}, {"role": "user", "content": f"Optimize this verbose engineering speech into grug speech:\n\n{verbose_input}"}] prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)inputs = tokenizer(prompt, return_tensors="pt").to("cuda") with torch.no_grad(): output_ids = model.generate(**inputs, max_new_tokens=150, do_sample=False) output = tokenizer.decode(output_ids[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)print(output)