File size: 5,356 Bytes
106bc10
 
 
 
17c8683
 
106bc10
 
 
 
 
 
 
17c8683
 
 
 
 
106bc10
 
17c8683
106bc10
17c8683
106bc10
 
 
 
 
17c8683
106bc10
17c8683
106bc10
17c8683
106bc10
17c8683
 
 
 
 
 
 
106bc10
17c8683
106bc10
17c8683
106bc10
 
 
 
 
17c8683
 
 
106bc10
17c8683
106bc10
17c8683
 
 
106bc10
 
 
17c8683
 
 
 
106bc10
 
 
17c8683
 
 
 
 
 
 
 
 
106bc10
 
 
17c8683
106bc10
 
 
17c8683
 
 
 
 
1580567
17c8683
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
base_model: unsloth/gemma-4-E4B-it-unsloth-bnb-4bit
library_name: peft
pipeline_tag: text-generation
language:
- en
tags:
- base_model:adapter:unsloth/gemma-4-E4B-it-unsloth-bnb-4bit
- lora
- sft
- transformers
- trl
- unsloth
- gemma
- android
- adb
- function-calling
- tool-use
---

# DroidADB: Gemma 4 E4B LoRA for Android/ADB Tool Calling

DroidADB is a LoRA adapter for Gemma 4 E4B Instruct. It chats normally, and when a request involves Android or ADB it calls an `adb` function tool instead of just printing a command. This is a personal project, trained on a personal Google Colab T4 GPU. It isn't affiliated with or funded by any organization.

## Model Details

### Model Description

This adapter was trained with supervised fine-tuning (SFT) using Unsloth and TRL. It uses Gemma 4's native function-calling format. Each training conversation has this shape:

user request → `adb` tool call → tool result → final assistant reply

A small set of general chat examples was mixed in so the model can still hold a normal conversation.

- **Developed by:** Muneesh Kanimbakam
- **Funded by:** Self-funded (personal project)
- **Shared by:** Muneesh Kanimbakam
- **Model type:** Causal LM, LoRA adapter (PEFT), function-calling / tool-use
- **Language(s):** English
- **License:** <TODO: must match the base Gemma 4 license>
- **Finetuned from model:** `unsloth/gemma-4-E4B-it`, loaded in 4-bit (resolved to `unsloth/gemma-4-E4B-it-unsloth-bnb-4bit`)

### Model Sources

- **Repository:** https://huggingface.co/<HF_USERNAME>/<MODEL_NAME>

## Uses

### Direct Use

- Turning natural-language Android requests into `adb` tool calls, e.g. "list installed packages", "show device logs", "get the battery status"
- General conversation, such as simple explanations, planning and summaries
- Serving as the model in a host app's tool loop: the host runs the tool and the model answers using the tool result

### Downstream Use

- Plugging into any agent framework that supports OpenAI/Gemma-style function tools
- Adding more tools through a tool registry (`register_tool`) without retraining
- Exporting to GGUF (`q4_k_m`) for llama.cpp or Ollama

### Out-of-Scope Use

- Running ADB commands automatically without a human approving them
- Rooting a device, modifying system partitions, or bypassing device security
- Production device management, or any high-stakes or safety-critical use
- Non-Android technical tasks that need expert accuracy

## Bias, Risks, and Limitations

- **Risk of wrong commands:** the model may produce ADB commands that are incorrect, outdated, or harmful. Always review a command before running it.
- **The adapter itself doesn't execute anything.** Safety comes from the host runtime. The reference runtime in the notebook:
  - dry-runs by default (`ALLOW_COMMAND_EXECUTION = False`)
  - accepts only commands that start with `adb`
  - blocks shell operators (`|`, `;`, `&&`, `||`, `>`, `>>`) and runs without `shell=True`
  - asks for confirmation before risky commands (`install`, `uninstall`, `rm`, `mv`, `reboot`, `settings put`, `chmod`, `chown`, `su`, `wipe`, `format`, `pm clear`)
- **Synthetic tool results:** in training, every tool result was a placeholder that said the command was not executed. The model never saw real device output, so it may handle real outputs poorly.
- **Limited general chat:** only 4 general-chat examples were included, so conversational quality relies mostly on the base model.
- Inherits the biases and limitations of the base Gemma model. 4-bit quantization may slightly reduce quality.

### Recommendations

Keep execution turned off by default. Require a human to approve each command, and pin the target device (`ADB_SERIAL`). Prefer read-only diagnostic commands.

## How to Get Started with the Model

```python
from unsloth import FastModel
from unsloth.chat_templates import get_chat_template

model, tokenizer = FastModel.from_pretrained(
    model_name=""Muneeshk/gemma-4-adb-agent"",
    max_seq_length=4096,
    load_in_4bit=True,
)
tokenizer = get_chat_template(tokenizer, chat_template="gemma-4")
FastModel.for_inference(model)

ADB_TOOL = {
    "type": "function",
    "function": {
        "name": "adb",
        "description": "Run one Android Debug Bridge command on an explicitly selected device.",
        "parameters": {
            "type": "object",
            "properties": {
                "command": {"type": "string", "description": "Full command beginning with adb. Never include a shell pipeline."},
                "confirm": {"type": "boolean", "description": "Set true only after user explicitly confirms a risky command."},
            },
            "required": ["command"],
        },
    },
}

messages = [
    {"role": "system", "content": "You are DroidADB, a friendly general-purpose assistant with strong Android and ADB expertise."},
    {"role": "user", "content": "How do I list all installed Android packages?"},
]
inputs = tokenizer.apply_chat_template(
    messages, tools=[ADB_TOOL], tokenize=True, add_generation_prompt=True,
    return_dict=True, return_tensors="pt",
).to(model.device)

out = model.generate(**inputs, max_new_tokens=256, do_sa**le=True,
                     tem**rature=1.0, top_p=0.95, top_k=64,**se_cache=True)
print(tokenizer.de**de(out[0][inputs["input_ids"].shape[-1\]:], skip_special_tokens=Fals**)