from transformers import AutoProcessor, AutoModelForMultimodalLMfrom peft import PeftModelimport torch # Load base + adapterbase = AutoModelForMultimodalLM.from_pretrained( "google/gemma-4-E4B-it", torch_dtype=torch.bfloat16, device_map="auto",)model = PeftModel.from_pretrained(base, "roshangrewal/gemma4-e4b-toolcall-v02-lora")model.eval() processor = AutoProcessor.from_pretrained("google/gemma-4-E4B-it") # Define tools and querytools = [{"type": "function", "function": { "name": "get_weather", "description": "Get weather for a city", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}}}]messages = [{"role": "user", "content": "What's the weather in Mumbai?"}] text = processor.apply_chat_template(messages, tools=tools, tokenize=False, add_generation_prompt=True)inputs = processor(text=text, return_tensors="pt").to(model.device) output = model.generate(**inputs, max_new_tokens=200, do_sample=False)print(processor.decode(output[0][inputs["input_ids"].shape[1]:], skip_special_tokens=False))# <|tool_call>call:get_weather{city:<|"|>Mumbai<|"|>}<tool_call|>