Spaces:
Running
Running
File size: 17,700 Bytes
550ed76 |
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# AI SBOM Generator System Architecture
## Overview
The AI SBOM Generator is a configurable system that automatically generates Software Bill of Materials (SBOM) documents for AI models hosted on HuggingFace. The system uses a registry-driven architecture that allows for dynamic field configuration without code changes.
## System Architecture
### Core Components
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI SBOM Generator β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Web Interface (FastAPI + HTML Templates) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β API Layer β
β βββ Generation Endpoints β
β βββ Scoring Endpoints β
β βββ Batch Processing β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Core Generation Engine β
β βββ AIBOMGenerator (generator.py) β
β βββ Enhanced Extractor (enhanced_extractor.py) β
β βββ Field Registry Manager (field_registry_manager.py)β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Configuration Layer β
β βββ Field Registry (field_registry.json) β
β βββ Scoring Configuration β
β βββ AIBOM Generation Rules β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Data Sources β
β βββ HuggingFace API β
β βββ Model Cards β
β βββ Configuration Files β
β βββ README Content β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
### Key Features
- **Registry-Driven Configuration**: All fields and scoring rules defined in JSON
- **Multi-Strategy Extraction**: 6 different extraction methods per field
- **Standards Compliance**: CycloneDX 1.6 compatible output
- **Configurable Scoring**: Weighted scoring system with tier-based multipliers
- **Automatic Field Discovery**: New fields added to registry are automatically processed
- **Comprehensive Logging**: Detailed extraction and scoring logs for debugging
## Process Workflow
### 1. System Initialization
```
System Initialization Process:
βββββββββββββββββββββ
β System Startup β
βββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββββ
β Load Field β
β Registry β
βββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββββ
β Initialize β
β Registry Manager β
βββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββ
β Load Scoring β
β Configuration β
βββββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββββ
β Initialize β
β Enhanced β
β Extractor β
βββββββββββ¬ββββββββ
β
βΌ
βββββββββββββββββββ
β System Ready β
βββββββββββββββββββ
```
**Steps:**
1. **Load Field Registry**: Read `field_registry.json` containing all field definitions
2. **Initialize Registry Manager**: Create manager instance with loaded configuration
3. **Load Scoring Configuration**: Parse scoring weights, tiers, and category definitions
4. **Initialize Enhanced Extractor**: Create extractor with registry-driven field discovery
5. **System Ready**: All components initialized and ready for SBOM generation
### 2. SBOM Generation Process
```
SBOM Generation Workflow:
User Request βββ
β
βΌ
βββββββββββββββββββββ ββββββββββββββββββββββ ββββββββββββββββββββ
β Validate Model βββββββΆβ Fetch Model Info βββββΆβ Initialize β
β ID β β β β Enhanced β
βββββββββββββββββββββ ββββββββββββββββββββββ β Extractor β
ββββββββββββ¬ββββββββ
β
βββββββββββββββββββββ ββββββββββββββββββββ β
β Return SBOM + ββββββ Calculate βββββββββββββββββββ
β Score β β Completeness β
βββββββββββββββββββββ β Score β
ββββββββββββββββββββ
β²
β
ββββββββββββββββββββββ
β Generate AIBOM β
β Structure β
ββββββββββββββββββββββ
β²
β
ββββββββββββββββββββββ
β Multi-Strategy β
β Field Processing β
ββββββββββββββββββββββ
β²
β
ββββββββββββββββββββββ
β Registry-Driven β
β Extraction β
ββββββββββββββββββββββ
```
#### 2.1 Model Information Gathering
**Input**: HuggingFace model ID (e.g., `deepseek-ai/DeepSeek-R1`)
**Process**:
1. **Validate Model ID**: Check format and accessibility
2. **Fetch Model Info**: Retrieve metadata from HuggingFace API
3. **Download Model Card**: Get structured model documentation
4. **Fetch Configuration Files**: Download `config.json`, `tokenizer_config.json`
5. **Extract README Content**: Parse model description and documentation
#### 2.2 Registry-Driven Field Extraction
**For each of the 29 registry fields:**
```
Multi-Strategy Field Extraction:
Field from Registry
β
βΌ
βββββββββββββββββββββ Success?
β Strategy 1: ββββββββββ
β HuggingFace API β β
βββββββββββββββββββββ β
β β
β Failure β
βΌ β
βββββββββββββββββββββ β
β Strategy 2: β β
β Model Card β β
βββββββββββββββββββββ β
β β
β Failure β
βΌ β
βββββββββββββββββββββ β
β Strategy 3: β β
β Config Files β β
βββββββββββββββββββββ β
β β
β Failure β
βΌ β
βββββββββββββββββββββ β
β Strategy 4: β β
β Text Patterns β β
βββββββββββββββββββββ β
β β
β Failure β
βΌ β
βββββββββββββββββββββ β
β Strategy 5: β β
β Intelligent β β
β Inference β β
βββββββββββββββββββββ β
β β
β Failure β
βΌ β
βββββββββββββββββββββ β
β Strategy 6: β β
β Fallback Value β β
βββββββββββββββββββββ β
β β
βΌ β
ββββββββββββββββββββββββββββββ
β Store Result & β
β Log Outcome β
βββββββββββββββββββββ
```
**Extraction Strategies**:
1. **HuggingFace API Extraction**
- Direct field mapping from API response
- High confidence, structured data
- Fields: `name`, `author`, `license`, `tags`, etc.
2. **Model Card Extraction**
- Parse structured model card YAML/metadata
- Medium-high confidence
- Fields: `limitation`, `metrics`, `datasets`, etc.
3. **Configuration File Extraction**
- Mine technical details from config files
- High confidence for technical fields
- Fields: `typeOfModel`, `hyperparameter`, etc.
4. **Text Pattern Extraction**
- Regex-based extraction from README content
- Medium confidence, requires validation
- Fields: `safetyRiskAssessment`, `informationAboutTraining`, etc.
5. **Intelligent Inference**
- Smart defaults based on model characteristics
- Medium confidence, contextual
- Fields: `primaryPurpose`, `domain`, etc.
6. **Fallback Values**
- Placeholder values when no data available
- Low/no confidence, maintains structure
- Ensures complete SBOM structure
#### 2.3 AIBOM Structure Generation
**Process**:
1. **Create Base Structure**: Initialize CycloneDX 1.6 compliant structure
2. **Populate Metadata Section**: Add extracted metadata fields
3. **Build Component Section**: Create model component with extracted data
4. **Add Model Card**: Include AI-specific model card information
5. **Generate External References**: Add distribution and repository links
6. **Create Dependencies**: Define model dependencies and relationships
7. **Validate Structure**: Ensure CycloneDX compliance
**Output Structure**:
```json
{
"bomFormat": "CycloneDX",
"specVersion": "1.6",
"serialNumber": "urn:uuid:...",
"version": 1,
"metadata": {
"timestamp": "...",
"tools": [...],
"component": {...},
"properties": [...]
},
"components": [{
"type": "machine-learning-model",
"name": "...",
"modelCard": {...},
"properties": [...]
}],
"externalReferences": [...],
"dependencies": [...]
}
```
### 3. Completeness Scoring Process
```
Completeness Scoring Process:
βββββββββββββββββββββ
β Extracted Fields β
βββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββββ
β Categorize β
β Fields β
βββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββββ
β Apply Tier β
β Weights β
β β’ Critical: 3x β
β β’ Important: 2x β
β β’ Supplement: 1x β
βββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββββ
β Calculate β
β Category Scores β
β β’ Required: 20 β
β β’ Metadata: 20 β
β β’ Basic: 20 β
β β’ ModelCard: 30 β
β β’ ExtRefs: 10 β
βββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββββ
β Sum Weighted β
β Scores β
β (Max: 100) β
βββββββββββ¬ββββββββββ
β
βΌ
βββββββββββββββββββββ
β Generate Score β
β Report β
βββββββββββββββββββββ
```
**Scoring Algorithm**:
1. **Field Categorization**: Group fields by category (required_fields, metadata, etc.)
2. **Tier Weight Application**: Apply multipliers (Critical: 3x, Important: 2x, Supplementary: 1x)
3. **Category Score Calculation**: `(Fields Present / Total Fields) Γ Category Weight`
4. **Final Score**: Sum of all category scores (max 100)
**Category Weights**:
- Required Fields: 20 points
- Metadata: 20 points
- Component Basic: 20 points
- Component Model Card: 30 points
- External References: 10 points
### 4. Output Generation
**Generated Artifacts**:
1. **AIBOM JSON**: CycloneDX 1.6 compliant SBOM document
2. **Completeness Score**: Numerical score (0-100) with breakdown
3. **Field Checklist**: Detailed field-by-field analysis
4. **Extraction Report**: Confidence levels and data sources
5. **Validation Results**: Compliance and quality checks
## Configuration Management
### Field Registry Structure
The system is driven by `field_registry.json` which defines:
- **Field Definitions**: All 29 extractable fields
- **Scoring Configuration**: Weights, tiers, and categories
- **AIBOM Generation Rules**: Structure and validation rules
- **Extraction Strategies**: How each field should be extracted
### Dynamic Configuration
**Adding New Fields**:
1. Add field definition to `field_registry.json`
2. System automatically discovers and attempts extraction
3. No code changes required
**Updating Scoring**:
1. Modify weights in registry configuration
2. Changes take effect immediately
3. Consistent scoring across all models
## Quality Assurance
### Validation Layers
1. **Input Validation**: Model ID format and accessibility
2. **Extraction Validation**: Data type and format checking
3. **Structure Validation**: CycloneDX schema compliance
4. **Scoring Validation**: Mathematical correctness
5. **Output Validation**: JSON schema and completeness
### Error Handling
- **Individual Field Failures**: Don't stop overall processing
- **Graceful Degradation**: Fallback to lower-confidence strategies
- **Comprehensive Logging**: Detailed error tracking and debugging
- **Recovery Mechanisms**: Automatic retry and alternative approaches
## Performance Characteristics
### Typical Processing Times
- **Single Model**: 2-5 seconds
- **Batch Processing**: 10-50 models/minute
- **Registry Loading**: <1 second
- **Field Extraction**: 1-3 seconds per model
### Scalability Features
- **Concurrent Processing**: Multiple models processed simultaneously
- **Caching**: Model metadata and configuration caching
- **Rate Limiting**: Respectful API usage
- **Resource Management**: Memory and connection pooling
## Integration Points
### APIs
- **Generation API**: `/api/generate` - Single model AI SBOM generation, with download URL
- **Generation with Completness Score Report API**: `/api/generate-with-report` - Generation API with completness scoring report
- **Completness Score Report Only API**: `/api/models/{model_id}/score` - Get the completeness score for a model without generating AI SBOM
### Data Sources
- **HuggingFace Hub**: Primary model metadata source
- **Model Repositories**: Direct file access for configurations
- **Model Cards**: Structured documentation parsing
### Output Formats
- **CycloneDX JSON**: Primary SBOM format
- **Field Reports**: Human-readable analysis
- **CSV Exports**: Batch processing results
- **API Responses**: Structured JSON for integration
This architecture provides a robust, configurable, and standards-compliant solution for AI model SBOM generation with comprehensive field extraction and scoring capabilities.
|