On Device Model Training
Skill Profile
(Select at least one profile to enable specific modules)
Overview
On-Device Model Training enables training and updating machine learning models directly on edge devices without transferring raw data to the cloud. This approach is essential for privacy-sensitive applications, reduces bandwidth costs, enables personalized models, and provides continuous learning capabilities even in offline environments.
Why This Matters
- Data Privacy: Raw data never leaves the device, ensuring compliance with privacy regulations
- Bandwidth Efficiency: Only model updates (gradients) are transmitted, reducing bandwidth costs by 95-99%
- Personalization: Models adapt to individual user patterns, improving user experience
- Offline Learning: Continuous improvement without connectivity, enabling edge AI in remote locations
- Regulatory Compliance: Meets GDPR, HIPAA, and other data protection requirements by design
Core Concepts & Rules
1. Core Principles
- Follow established patterns and conventions
- Maintain consistency across codebase
- Document decisions and trade-offs
2. Implementation Guidelines
- Start with the simplest viable solution
- Iterate based on feedback and requirements
- Test thoroughly before deployment
Inputs / Outputs / Contracts
- Inputs:
- Initial global model (PyTorch/TensorFlow)
- Client configuration (server URL, training parameters)
- Local data on client devices
- Privacy parameters (epsilon, delta, noise scale)
- Entry Conditions:
- Server deployed and accessible
- Initial global model trained and available
- Client devices have sufficient compute/memory for local training
- Network connectivity between clients and server
- Privacy parameters configured and documented
- Outputs:
- Updated global model (aggregated from client updates)
- Model version tracking
- Training metrics (accuracy, loss, client participation)
- Privacy budget tracking
- Artifacts Required (Deliverables):
- Federated learning server implementation
- Client training implementation
- Privacy protection modules
- Configuration files (server, client)
- Monitoring and logging infrastructure
- Acceptance Evidence:
- Global model converges to target accuracy (> 90% of centralized)
- Privacy budget respected (epsilon < 5% per round)
- Client participation rate > 70%
- Round completion time < 5 minutes
- Update success rate > 95%
- Success Criteria:
- Model accuracy within 90-95% of centralized training
- Privacy guarantees maintained (differential privacy, secure aggregation)
- Bandwidth reduction > 95% vs data upload
- Client participation > 70% of active clients
- Round completion < 5 minutes
- Update success rate > 95%
Skill Composition
Quick Start / Implementation Example
- Review requirements and constraints
- Set up development environment
- Implement core functionality following patterns
- Write tests for critical paths
- Run tests and fix issues
- Document any deviations or decisions
# Example implementation following best practices
def example_function():
# Your implementation here
pass
Assumptions / Constraints / Non-goals
- Assumptions:
- Development environment is properly configured
- Required dependencies are available
- Team has basic understanding of domain
- Constraints:
- Must follow existing codebase conventions
- Time and resource limitations
- Compatibility requirements
- Non-goals:
- This skill does not cover edge cases outside scope
- Not a replacement for formal training
Compatibility & Prerequisites
- Supported Versions:
- Python 3.8+
- Node.js 16+
- Modern browsers (Chrome, Firefox, Safari, Edge)
- Required AI Tools:
- Code editor (VS Code recommended)
- Testing framework appropriate for language
- Version control (Git)
- Dependencies:
- Language-specific package manager
- Build tools
- Testing libraries
- Environment Setup:
.env.example keys: API_KEY, DATABASE_URL (no values)
Test Scenario Matrix (QA Strategy)
| Type |
Focus Area |
Required Scenarios / Mocks |
| Unit |
Core Logic |
Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |
| Integration |
DB / API |
All external API calls or database connections must be mocked during unit tests |
| E2E |
User Journey |
Critical user flows to test |
| Performance |
Latency / Load |
Benchmark requirements |
| Security |
Vuln / Auth |
SAST/DAST or dependency audit |
| Frontend |
UX / A11y |
Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |
Technical Guardrails & Security Threat Model
1. Security & Privacy (Threat Model)
- Top Threats: Injection attacks, authentication bypass, data exposure
2. Performance & Resources
3. Architecture & Scalability
4. Observability & Reliability
Agent Directives & Error Recovery
(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)
- Thinking Process: Analyze root cause before fixing. Do not brute-force.
- Fallback Strategy: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.
- Self-Review: Check against Guardrails & Anti-patterns before finalizing.
- Output Constraints: Output ONLY the modified code block. Do not explain unless asked.
Definition of Done (DoD) Checklist
Anti-patterns / Pitfalls
- ⛔ Don't: Log PII, catch-all exception, N+1 queries
- ⚠️ Watch out for: Common symptoms and quick fixes
- 💡 Instead: Use proper error handling, pagination, and logging
Reference Links & Examples
- Internal documentation and examples
- Official documentation and best practices
- Community resources and discussions
Versioning & Changelog
- Version: 1.0.0
- Changelog:
- 2026-02-22: Initial version with complete template structure
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: on-device-model-training3description: On-Device Model Training enables training and updating machine learning Use when this capability is needed.4---56# On Device Model Training78## Skill Profile9*(Select at least one profile to enable specific modules)*10- [ ] **DevOps**11- [x] **Backend**12- [ ] **Frontend**13- [ ] **AI-RAG**14- [ ] **Security Critical**1516## Overview17On-Device Model Training enables training and updating machine learning models directly on edge devices without transferring raw data to the cloud. This approach is essential for privacy-sensitive applications, reduces bandwidth costs, enables personalized models, and provides continuous learning capabilities even in offline environments.1819## Why This Matters20- **Data Privacy**: Raw data never leaves the device, ensuring compliance with privacy regulations21- **Bandwidth Efficiency**: Only model updates (gradients) are transmitted, reducing bandwidth costs by 95-99%22- **Personalization**: Models adapt to individual user patterns, improving user experience23- **Offline Learning**: Continuous improvement without connectivity, enabling edge AI in remote locations24- **Regulatory Compliance**: Meets GDPR, HIPAA, and other data protection requirements by design2526---2728## Core Concepts & Rules2930### 1. Core Principles31- Follow established patterns and conventions32- Maintain consistency across codebase33- Document decisions and trade-offs3435### 2. Implementation Guidelines36- Start with the simplest viable solution37- Iterate based on feedback and requirements38- Test thoroughly before deployment394041## Inputs / Outputs / Contracts42* **Inputs**:43 - Initial global model (PyTorch/TensorFlow)44 - Client configuration (server URL, training parameters)45 - Local data on client devices46 - Privacy parameters (epsilon, delta, noise scale)47* **Entry Conditions**:48 - Server deployed and accessible49 - Initial global model trained and available50 - Client devices have sufficient compute/memory for local training51 - Network connectivity between clients and server52 - Privacy parameters configured and documented53* **Outputs**:54 - Updated global model (aggregated from client updates)55 - Model version tracking56 - Training metrics (accuracy, loss, client participation)57 - Privacy budget tracking58* **Artifacts Required (Deliverables)**:59 - Federated learning server implementation60 - Client training implementation61 - Privacy protection modules62 - Configuration files (server, client)63 - Monitoring and logging infrastructure64* **Acceptance Evidence**:65 - Global model converges to target accuracy (> 90% of centralized)66 - Privacy budget respected (epsilon < 5% per round)67 - Client participation rate > 70%68 - Round completion time < 5 minutes69 - Update success rate > 95%70* **Success Criteria**:71 - Model accuracy within 90-95% of centralized training72 - Privacy guarantees maintained (differential privacy, secure aggregation)73 - Bandwidth reduction > 95% vs data upload74 - Client participation > 70% of active clients75 - Round completion < 5 minutes76 - Update success rate > 95%7778## Skill Composition79* **Depends on**: [tinyml-microcontroller-ai](../tinyml-microcontroller-ai/SKILL.md) (Edge inference), [edge-model-compression](../edge-model-compression/SKILL.md) (Model optimization)80* **Compatible with**: [hybrid-inference-architecture](../hybrid-inference-architecture/SKILL.md), [edge-ai-development-workflow](../edge-ai-development-workflow/SKILL.md)81* **Conflicts with**: None82* **Related Skills**: [drift-detection-retraining](../../77-mlops-data-engineering/drift-detection-retraining/SKILL.md), [model-registry-versioning](../../77-mlops-data-engineering/model-registry-versioning/SKILL.md)8384---8586## Quick Start / Implementation Example87881. Review requirements and constraints892. Set up development environment903. Implement core functionality following patterns914. Write tests for critical paths925. Run tests and fix issues936. Document any deviations or decisions9495```python96# Example implementation following best practices97def example_function():98 # Your implementation here99 pass100```101102103## Assumptions / Constraints / Non-goals104105* **Assumptions**:106 - Development environment is properly configured107 - Required dependencies are available108 - Team has basic understanding of domain109* **Constraints**:110 - Must follow existing codebase conventions111 - Time and resource limitations112 - Compatibility requirements113* **Non-goals**:114 - This skill does not cover edge cases outside scope115 - Not a replacement for formal training116117118## Compatibility & Prerequisites119120* **Supported Versions**:121 - Python 3.8+122 - Node.js 16+123 - Modern browsers (Chrome, Firefox, Safari, Edge)124* **Required AI Tools**:125 - Code editor (VS Code recommended)126 - Testing framework appropriate for language127 - Version control (Git)128* **Dependencies**:129 - Language-specific package manager130 - Build tools131 - Testing libraries132* **Environment Setup**:133 - `.env.example` keys: `API_KEY`, `DATABASE_URL` (no values)134135136## Test Scenario Matrix (QA Strategy)137138| Type | Focus Area | Required Scenarios / Mocks |139| :--- | :--- | :--- |140| **Unit** | Core Logic | Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |141| **Integration** | DB / API | All external API calls or database connections must be mocked during unit tests |142| **E2E** | User Journey | Critical user flows to test |143| **Performance** | Latency / Load | Benchmark requirements |144| **Security** | Vuln / Auth | SAST/DAST or dependency audit |145| **Frontend** | UX / A11y | Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |146147148## Technical Guardrails & Security Threat Model149150### 1. Security & Privacy (Threat Model)151* **Top Threats**: Injection attacks, authentication bypass, data exposure152- [ ] **Data Handling**: Sanitize all user inputs to prevent Injection attacks. Never log raw PII153- [ ] **Secrets Management**: No hardcoded API keys. Use Env Vars/Secrets Manager154- [ ] **Authorization**: Validate user permissions before state changes155156### 2. Performance & Resources157- [ ] **Execution Efficiency**: Consider time complexity for algorithms158- [ ] **Memory Management**: Use streams/pagination for large data159- [ ] **Resource Cleanup**: Close DB connections/file handlers in finally blocks160161### 3. Architecture & Scalability162- [ ] **Design Pattern**: Follow SOLID principles, use Dependency Injection163- [ ] **Modularity**: Decouple logic from UI/Frameworks164165### 4. Observability & Reliability166- [ ] **Logging Standards**: Structured JSON, include trace IDs `request_id`167- [ ] **Metrics**: Track `error_rate`, `latency`, `queue_depth`168- [ ] **Error Handling**: Standardized error codes, no bare except169- [ ] **Observability Artifacts**:170 - **Log Fields**: timestamp, level, message, request_id171 - **Metrics**: request_count, error_count, response_time172 - **Dashboards/Alerts**: High Error Rate > 5%173174175## Agent Directives & Error Recovery176*(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)*177178- **Thinking Process**: Analyze root cause before fixing. Do not brute-force.179- **Fallback Strategy**: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.180- **Self-Review**: Check against Guardrails & Anti-patterns before finalizing.181- **Output Constraints**: Output ONLY the modified code block. Do not explain unless asked.182183184## Definition of Done (DoD) Checklist185186- [ ] Tests passed + coverage met187- [ ] Lint/Typecheck passed188- [ ] Logging/Metrics/Trace implemented189- [ ] Security checks passed190- [ ] Documentation/Changelog updated191- [ ] Accessibility/Performance requirements met (if frontend)192193194## Anti-patterns / Pitfalls195196* ⛔ **Don't**: Log PII, catch-all exception, N+1 queries197* ⚠️ **Watch out for**: Common symptoms and quick fixes198* 💡 **Instead**: Use proper error handling, pagination, and logging199200201## Reference Links & Examples202203* Internal documentation and examples204* Official documentation and best practices205* Community resources and discussions206207208## Versioning & Changelog209210* **Version**: 1.0.0211* **Changelog**:212 - 2026-02-22: Initial version with complete template structure213214---215> Converted and distributed by [TomeVault](https://tomevault.io/claim/amnadtaowsoam) — claim your Tome and manage your conversions.216<!-- tomevault:4.0:skill_md:2026-04-13 -->