This is a fine-tuned version of google/gemma-2-2b-it, optimized for on-device cybersecurity applications for mobile devices. Unlike standard chatbots, this model is trained to output structured JSON actions (e.g., scan_url, isolate_network) that can be executed by an Android app or Edge AI Service.
The model has been adapted using Supervised Fine-Tuning (SFT) and DPO (Direct Preference Optimization) with LoRA (Low-Rank Adaptation) techniques to maintain high performance while remaining efficient for mobile and edge devices.
Key Technologies
Unsloth: Used for ultra-fast, memory-efficient fine-tuning (2x faster, 70% less memory)
LiteRT (formerly TFLite): Model format compatible with Google AI Edge Gallery for on-device inference
LoRA (Low-Rank Adaptation): Parameter-efficient fine-tuning to keep the model lightweight
Model Details
Base Model: google/gemma-2-2b-it
Model Size: 2 billion parameters (~2GB)
Model Type: Causal Language Model (Gemma2ForCausalLM)
Extract the action field to determine what security action to take
Extract the params object to get necessary parameters (URL, process ID, etc.)
Extract the thought field for logging/debugging
3. Execute Security Actions
Based on the action specified, your application implements the actual security function:
scan_url(url): Integrate with a URL scanning service (e.g., Google Safe Browsing API, VirusTotal) to check if the link is malicious
kill_process(pid): Use Android's ActivityManager or system APIs to terminate the suspicious application process
isolate_network(): Disable network connectivity using ConnectivityManager or firewall APIs to prevent data exfiltration
ignore(): No action needed - log the event and continue normal operation
Important: The model does NOT perform these actions itself. It only generates the instructions. Your application must implement the actual security mechanisms.
Usage
Python
python
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
34model_id ="jprtr/gemma-2-2b-it-CyberAgent"56tokenizer = AutoTokenizer.from_pretrained(model_id)7model = AutoModelForCausalLM.from_pretrained(8 model_id,9 device_map="auto",10 torch_dtype=torch.bfloat16,11)1213# Security agent prompt14agent_prompt ="""You are an autonomous security agent on a Pixel device.
15Analyze the user's input. If a threat is detected, output a JSON action block.
16Available Actions:
17- scan_url(url): Check a link for phishing.
18- kill_process(pid): Stop a suspicious app.
19- isolate_network(): Cut off internet access.
20- ignore(): No threat found.
2122### Instruction:
23{}
24### Input:
25{}
26### Response:
27{}"""2829input_text ="Check this suspicious link: bit.ly/malware-site"30prompt = agent_prompt.format(input_text,"","")3132inputs = tokenizer([prompt], return_tensors="pt").to("cuda")33outputs = model.generate(**inputs, max_new_tokens=128, use_cache=True)34response = tokenizer.batch_decode(outputs)[0].split("### Response:")[1].strip()35print(response)
Training Notebook
The complete training pipeline is available on GitHub: