jprtr commited on
Commit
3c42913
·
verified ·
1 Parent(s): 296b470

Restore complete model card from commit 69fc49b

Browse files
Files changed (1) hide show
  1. README.md +147 -150
README.md CHANGED
@@ -1,211 +1,208 @@
1
  ---
2
- base_model: unsloth/gemma-2-2b-it-bnb-4bit
3
- library_name: peft
4
- pipeline_tag: text-generation
5
- tags:
6
- - base_model:adapter:unsloth/gemma-2-2b-it-bnb-4bit
7
- - dpo
8
- - lora
9
- - sft
10
- - transformers
11
- - trl
12
- - unsloth
13
  ---
14
 
15
- # Model Card for Model ID
16
 
17
- <!-- Provide a quick summary of what the model is/does. -->
18
 
 
19
 
 
20
 
21
- ## Model Details
22
-
23
- ### Model Description
24
-
25
- <!-- Provide a longer summary of what this model is. -->
26
-
27
-
28
-
29
- - **Developed by:** [More Information Needed]
30
- - **Funded by [optional]:** [More Information Needed]
31
- - **Shared by [optional]:** [More Information Needed]
32
- - **Model type:** [More Information Needed]
33
- - **Language(s) (NLP):** [More Information Needed]
34
- - **License:** [More Information Needed]
35
- - **Finetuned from model [optional]:** [More Information Needed]
36
-
37
- ### Model Sources [optional]
38
-
39
- <!-- Provide the basic links for the model. -->
40
-
41
- - **Repository:** [More Information Needed]
42
- - **Paper [optional]:** [More Information Needed]
43
- - **Demo [optional]:** [More Information Needed]
44
-
45
- ## Uses
46
-
47
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
48
-
49
- ### Direct Use
50
-
51
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
52
-
53
- [More Information Needed]
54
-
55
- ### Downstream Use [optional]
56
-
57
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
58
-
59
- [More Information Needed]
60
-
61
- ### Out-of-Scope Use
62
-
63
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
64
-
65
- [More Information Needed]
66
 
67
- ## Bias, Risks, and Limitations
 
 
68
 
69
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
70
-
71
- [More Information Needed]
72
-
73
- ### Recommendations
74
-
75
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
76
-
77
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
78
-
79
- ## How to Get Started with the Model
80
-
81
- Use the code below to get started with the model.
82
-
83
- [More Information Needed]
84
-
85
- ## Training Details
86
-
87
- ### Training Data
88
-
89
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
90
-
91
- [More Information Needed]
92
-
93
- ### Training Procedure
94
-
95
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
96
-
97
- #### Preprocessing [optional]
98
-
99
- [More Information Needed]
100
-
101
-
102
- #### Training Hyperparameters
103
-
104
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
105
 
106
- #### Speeds, Sizes, Times [optional]
 
 
 
 
 
 
 
107
 
108
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
109
 
110
- [More Information Needed]
111
 
112
- ## Evaluation
113
 
114
- <!-- This section describes the evaluation protocols and provides the results. -->
 
 
 
 
115
 
116
- ### Testing Data, Factors & Metrics
117
 
118
- #### Testing Data
 
 
119
 
120
- <!-- This should link to a Dataset Card if possible. -->
121
 
122
- [More Information Needed]
 
 
123
 
124
- #### Factors
125
 
126
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
127
 
128
- [More Information Needed]
 
 
 
129
 
130
- #### Metrics
131
 
132
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
133
 
134
- [More Information Needed]
135
 
136
- ### Results
 
 
 
 
 
 
137
 
138
- [More Information Needed]
139
 
140
- #### Summary
141
 
 
142
 
 
143
 
144
- ## Model Examination [optional]
 
 
 
 
 
 
145
 
146
- <!-- Relevant interpretability work for the model goes here -->
147
 
148
- [More Information Needed]
 
 
 
 
149
 
150
- ## Environmental Impact
151
 
152
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
153
 
154
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
 
 
 
155
 
156
- - **Hardware Type:** [More Information Needed]
157
- - **Hours used:** [More Information Needed]
158
- - **Cloud Provider:** [More Information Needed]
159
- - **Compute Region:** [More Information Needed]
160
- - **Carbon Emitted:** [More Information Needed]
161
 
162
- ## Technical Specifications [optional]
163
 
164
- ### Model Architecture and Objective
165
 
166
- [More Information Needed]
 
 
167
 
168
- ### Compute Infrastructure
169
 
170
- [More Information Needed]
 
 
 
 
 
171
 
172
- #### Hardware
 
 
 
 
 
 
 
173
 
174
- [More Information Needed]
 
 
 
 
 
175
 
176
- #### Software
 
177
 
178
- [More Information Needed]
 
 
 
 
179
 
180
- ## Citation [optional]
181
 
182
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
183
 
184
- **BibTeX:**
 
 
185
 
186
- [More Information Needed]
187
 
188
- **APA:**
 
 
 
 
 
189
 
190
- [More Information Needed]
191
 
192
- ## Glossary [optional]
 
 
 
193
 
194
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
195
 
196
- [More Information Needed]
 
 
 
 
197
 
198
- ## More Information [optional]
199
 
200
- [More Information Needed]
 
 
201
 
202
- ## Model Card Authors [optional]
203
 
204
- [More Information Needed]
205
 
206
- ## Model Card Contact
 
 
 
 
 
 
 
 
207
 
208
- [More Information Needed]
209
- ### Framework versions
210
 
211
- - PEFT 0.18.0
 
1
  ---
2
+ {}
 
 
 
 
 
 
 
 
 
 
3
  ---
4
 
5
+ # Gemma-2-2B-IT-CyberAgent
6
 
7
+ ## Model Description
8
 
9
+ 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.
10
 
11
+ 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.
12
 
13
+ ## Key Technologies
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
+ - **Unsloth**: Used for ultra-fast, memory-efficient fine-tuning (2x faster, 70% less memory)
16
+ - **LiteRT (formerly TFLite)**: Model format compatible with Google AI Edge Gallery for on-device inference
17
+ - **LoRA (Low-Rank Adaptation)**: Parameter-efficient fine-tuning to keep the model lightweight
18
 
19
+ ## Model Details
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ - **Base Model**: google/gemma-2-2b-it
22
+ - **Model Size**: 2 billion parameters (~2GB)
23
+ - **Model Type**: Causal Language Model (Gemma2ForCausalLM)
24
+ - **Fine-tuning Method**: LoRA + SFT + DPO
25
+ - **Optimization**: Mobile-first deployment
26
+ - **Precision**: bfloat16 / 4-bit quantization
27
+ - **Context Length**: 2048 tokens (training) / 8192 tokens (max)
28
+ - **Hardware Requirements**: GPU (L4/T4 recommended for training)
29
 
30
+ ## Training
31
 
32
+ This model was fine-tuned with the following techniques:
33
 
34
+ ### Supervised Fine-Tuning (SFT)
35
 
36
+ - **Training Steps**: 600 steps
37
+ - **Dataset**: Custom cybersecurity dataset with 2000+ threat examples
38
+ - **Focus**: Task-specific instruction tuning for security actions
39
+ - **Learning Rate**: 5e-5 (stable convergence)
40
+ - **Batch Size**: 2 with gradient accumulation (4 steps)
41
 
42
+ ### DPO Training (Refining the Agent)
43
 
44
+ - **Training Steps**: 150 steps
45
+ - **Purpose**: Refine model responses for better alignment
46
+ - **Technique**: Direct Preference Optimization
47
 
48
+ ### Data Preparation
49
 
50
+ - Clean synthetic dataset with EOS tokens
51
+ - Hard negatives for improved discrimination
52
+ - Structured JSON output format training
53
 
54
+ ## Available Security Actions
55
 
56
+ The model can output these security actions:
57
 
58
+ - `scan_url(url)`: Check a link for phishing
59
+ - `kill_process(pid)`: Stop a suspicious app
60
+ - `isolate_network()`: Cut off internet access
61
+ - `ignore()`: No threat detected
62
 
63
+ ## Input/Output Format
64
 
65
+ **Input**: Natural language threat description
66
 
67
+ **Output**: JSON action block
68
 
69
+ ```json
70
+ {
71
+ "thought": "Suspicious URL detected",
72
+ "action": "scan_url",
73
+ "params": {"url": "bit.ly/malware-site"}
74
+ }
75
+ ```
76
 
77
+ ## Implementation Workflow
78
 
79
+ This model outputs JSON action blocks that your application must parse and execute. Here's the complete workflow:
80
 
81
+ ### 1. Model Generates JSON Instructions
82
 
83
+ When you send user input to the model (e.g., "Check this suspicious link: bit.ly/malware-site"), it analyzes the threat and outputs structured JSON:
84
 
85
+ ```json
86
+ {
87
+ "thought": "Suspicious URL detected",
88
+ "action": "scan_url",
89
+ "params": {"url": "bit.ly/malware-site"}
90
+ }
91
+ ```
92
 
93
+ ### 2. Application Parses JSON
94
 
95
+ Your Android app or Edge AI Service must:
96
+ - Parse the JSON response from the model
97
+ - Extract the `action` field to determine what security action to take
98
+ - Extract the `params` object to get necessary parameters (URL, process ID, etc.)
99
+ - Extract the `thought` field for logging/debugging
100
 
101
+ ### 3. Execute Security Actions
102
 
103
+ Based on the action specified, your application implements the actual security function:
104
 
105
+ - **`scan_url(url)`**: Integrate with a URL scanning service (e.g., Google Safe Browsing API, VirusTotal) to check if the link is malicious
106
+ - **`kill_process(pid)`**: Use Android's `ActivityManager` or system APIs to terminate the suspicious application process
107
+ - **`isolate_network()`**: Disable network connectivity using `ConnectivityManager` or firewall APIs to prevent data exfiltration
108
+ - **`ignore()`**: No action needed - log the event and continue normal operation
109
 
110
+ **Important**: The model does NOT perform these actions itself. It only generates the instructions. Your application must implement the actual security mechanisms.
 
 
 
 
111
 
112
+ ## Usage
113
 
114
+ ### Python
115
 
116
+ ```python
117
+ from transformers import AutoTokenizer, AutoModelForCausalLM
118
+ import torch
119
 
120
+ model_id = "jprtr/gemma-2-2b-it-CyberAgent"
121
 
122
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
123
+ model = AutoModelForCausalLM.from_pretrained(
124
+ model_id,
125
+ device_map="auto",
126
+ torch_dtype=torch.bfloat16,
127
+ )
128
 
129
+ # Security agent prompt
130
+ agent_prompt = """You are an autonomous security agent on a Pixel device.
131
+ Analyze the user's input. If a threat is detected, output a JSON action block.
132
+ Available Actions:
133
+ - scan_url(url): Check a link for phishing.
134
+ - kill_process(pid): Stop a suspicious app.
135
+ - isolate_network(): Cut off internet access.
136
+ - ignore(): No threat found.
137
 
138
+ ### Instruction:
139
+ {}
140
+ ### Input:
141
+ {}
142
+ ### Response:
143
+ {}"""
144
 
145
+ input_text = "Check this suspicious link: bit.ly/malware-site"
146
+ prompt = agent_prompt.format(input_text, "", "")
147
 
148
+ inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
149
+ outputs = model.generate(**inputs, max_new_tokens=128, use_cache=True)
150
+ response = tokenizer.batch_decode(outputs)[0].split("### Response:")[1].strip()
151
+ print(response)
152
+ ```
153
 
154
+ ## Training Notebook
155
 
156
+ The complete training pipeline is available on GitHub:
157
 
158
+ - **Repository**: [cyber-agent-gemma-2-2b-mobile](https://github.com/jprtr/cyber-agent-gemma-2-2b-mobile)
159
+ - **Notebook**: Production-ready Google Colab notebook with full training workflow
160
+ - **Open in Colab**: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://github.com/jprtr/cyber-agent-gemma-2-2b-mobile/blob/main/Gemma_2_2B_Cybersecurity_Agent_Mobile.ipynb)
161
 
162
+ ## Intended Use
163
 
164
+ - Mobile and edge device cybersecurity
165
+ - On-device AI security applications
166
+ - Autonomous threat detection and response
167
+ - Resource-constrained environments
168
+ - Android security agents
169
+ - Privacy-focused local inference
170
 
171
+ ## Performance
172
 
173
+ - **Training Time**: ~1-2 hours on L4 GPU
174
+ - **Model Size**: ~2GB (suitable for modern Android devices with 6GB+ RAM)
175
+ - **Inference Speed**: Optimized for on-device execution
176
+ - **Memory Efficiency**: 70% less memory usage with Unsloth optimization
177
 
178
+ ## Limitations
179
 
180
+ - This model inherits the limitations of the base Gemma 2-2B model
181
+ - Optimized for mobile deployment, performance may vary on different hardware
182
+ - As with all language models, outputs should be verified for accuracy
183
+ - AI Edge Torch conversion had compatibility issues - use PyTorch Mobile or ONNX Runtime instead
184
+ - Trained specifically for cybersecurity actions - not a general-purpose chatbot
185
 
186
+ ## Deployment Options
187
 
188
+ 1. **PyTorch Mobile** (recommended for Android)
189
+ 2. **ONNX Runtime Mobile**
190
+ 3. **TensorFlow Lite** (via ONNX conversion)
191
 
192
+ ## Citation
193
 
194
+ If you use this model, please cite both the original Gemma model and this fine-tuned version:
195
 
196
+ ```bibtex
197
+ @misc{gemma-2-2b-it-cyberagent,
198
+ author = {CyberAgent},
199
+ title = {Gemma-2-2B-IT-CyberAgent: Mobile Cybersecurity Agent},
200
+ year = {2025},
201
+ publisher = {HuggingFace},
202
+ url = {https://huggingface.co/jprtr/gemma-2-2b-it-CyberAgent}
203
+ }
204
+ ```
205
 
206
+ ## License
 
207
 
208
+ This model is released under the Gemma license. See the [Gemma Terms of Use](https://ai.google.dev/gemma/terms) for more details.