lumen-resources 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,249 @@
1
+ # Lumen Services Configuration Schema
2
+ # Version: 1.0.0
3
+ # Specification: https://json-schema.org/draft-07/schema
4
+
5
+ $schema: "http://json-schema.org/draft-07/schema#"
6
+ $id: "https://github.com/Lumilio-Photos/lumen-config-spec/v1.0.0"
7
+
8
+ title: Lumen Config
9
+ description: Unified configuration schema for all Lumen ML services
10
+
11
+ type: object
12
+ required:
13
+ - metadata
14
+ - deployment
15
+ - server
16
+ - services
17
+
18
+ properties:
19
+ metadata:
20
+ type: object
21
+ required:
22
+ - version
23
+ - region
24
+ - cache_dir
25
+ properties:
26
+ version:
27
+ type: string
28
+ pattern: "^\\d+\\.\\d+\\.\\d+$"
29
+ description: Configuration version (semantic versioning)
30
+ examples:
31
+ - "1.0.0"
32
+ - "2.1.3"
33
+
34
+ region:
35
+ type: string
36
+ enum: ["cn", "other"]
37
+ description: Platform region selection (cn=ModelScope, other=HuggingFace)
38
+
39
+ cache_dir:
40
+ type: string
41
+ description: Model cache directory path (supports ~ expansion)
42
+ examples:
43
+ - "~/.lumen/models"
44
+ - "/opt/lumen/models"
45
+
46
+ deployment:
47
+ type: object
48
+ required:
49
+ - mode
50
+ properties:
51
+ mode:
52
+ type: string
53
+ enum: ["single", "hub"]
54
+ description: Deployment mode
55
+
56
+ service:
57
+ type: string
58
+ description: Service name for single mode (required if mode=single)
59
+ pattern: "^[a-z][a-z0-9_]*$"
60
+
61
+ services:
62
+ type: array
63
+ items:
64
+ type: string
65
+ pattern: "^[a-z][a-z0-9_]*$"
66
+ minItems: 1
67
+ uniqueItems: true
68
+ description: Service names for hub mode (required if mode=hub)
69
+
70
+ # Conditional validation based on mode
71
+ oneOf:
72
+ - required: ["service"]
73
+ properties:
74
+ mode:
75
+ const: "single"
76
+ - required: ["services"]
77
+ properties:
78
+ mode:
79
+ const: "hub"
80
+
81
+ server:
82
+ type: object
83
+ required:
84
+ - port
85
+ properties:
86
+ port:
87
+ type: integer
88
+ minimum: 1024
89
+ maximum: 65535
90
+ default: 50051
91
+ description: gRPC server port
92
+
93
+ host:
94
+ type: string
95
+ default: "0.0.0.0"
96
+ description: Server bind address
97
+ examples:
98
+ - "0.0.0.0"
99
+ - "127.0.0.1"
100
+ - "[::]"
101
+
102
+ mdns:
103
+ type: object
104
+ properties:
105
+ enabled:
106
+ type: boolean
107
+ default: false
108
+ description: Enable mDNS service discovery
109
+
110
+ service_name:
111
+ type: string
112
+ description: mDNS service name (required if enabled=true)
113
+ pattern: "^[a-z][a-z0-9-]*$"
114
+ examples:
115
+ - "lumen-clip"
116
+ - "lumen-hub"
117
+
118
+ # If enabled=true, service_name is required
119
+ if:
120
+ properties:
121
+ enabled:
122
+ const: true
123
+ then:
124
+ required: ["service_name"]
125
+
126
+ services:
127
+ type: object
128
+ minProperties: 1
129
+ description: Service definitions
130
+
131
+ patternProperties:
132
+ "^[a-z][a-z0-9_]*$":
133
+ type: object
134
+ required:
135
+ - enabled
136
+ - package
137
+ - import
138
+ - models
139
+
140
+ properties:
141
+ enabled:
142
+ type: boolean
143
+ description: Whether to load this service
144
+
145
+ package:
146
+ type: string
147
+ pattern: "^[a-z][a-z0-9_]*$"
148
+ description: Python package name
149
+ examples:
150
+ - "lumen_clip"
151
+ - "lumen_face"
152
+
153
+ import:
154
+ type: object
155
+ required:
156
+ - registry_class
157
+ - add_to_server
158
+ properties:
159
+ registry_class:
160
+ type: string
161
+ pattern: "^[a-z_][a-z0-9_.]*\\.[A-Z][a-zA-Z0-9]*$"
162
+ description: Full dotted path to service registry class
163
+ examples:
164
+ - "lumen_clip.service_registry.ClipService"
165
+ - "lumen_face.service_registry.FaceService"
166
+
167
+ add_to_server:
168
+ type: string
169
+ pattern: "^[a-z_][a-z0-9_.]*\\.add_[A-Za-z0-9_]+_to_server$"
170
+ description: Full dotted path to gRPC add_to_server function
171
+ examples:
172
+ - "lumen_clip.proto.ml_service_pb2_grpc.add_InferenceServicer_to_server"
173
+ - "lumen_face.proto.ml_service_pb2_grpc.add_FaceServicer_to_server"
174
+ backend_settings:
175
+ $ref: "#/definitions/BackendSettings"
176
+ models:
177
+ type: object
178
+ minProperties: 1
179
+ description: Model configurations (alias → config)
180
+
181
+ patternProperties:
182
+ "^[a-z][a-z0-9_]*$":
183
+ $ref: "#/definitions/ModelConfig"
184
+
185
+ definitions:
186
+ BackendSettings:
187
+ type: object
188
+ description: Optional settings for inference backend configuration.
189
+ properties:
190
+ device:
191
+ type: [string, "null"] # Allow string or null
192
+ description: "Preferred device ('cuda', 'mps', 'cpu'). If null, auto-detects best available."
193
+ default: null
194
+ batch_size:
195
+ type: integer
196
+ description: Maximum batch size for inference.
197
+ minimum: 1
198
+ default: 8
199
+ onnx_providers:
200
+ type: [array, "null"] # Allow array or null
201
+ items:
202
+ type: string
203
+ description: "List of ONNX execution providers. If null, uses ONNX Runtime defaults."
204
+ default: null
205
+ additionalProperties: false
206
+ ModelConfig:
207
+ type: object
208
+ required:
209
+ - model
210
+ - runtime
211
+ properties:
212
+ model:
213
+ type: string
214
+ description: Model repository name
215
+ examples:
216
+ - "ViT-B-32"
217
+ - "CN-CLIP-ViT-B-16"
218
+ - "MobileCLIP-S2"
219
+
220
+ runtime:
221
+ type: string
222
+ enum: ["torch", "onnx", "rknn"]
223
+ description: Model runtime type
224
+
225
+ rknn_device:
226
+ type: string
227
+ pattern: "^rk\\d+$"
228
+ description: RKNN device identifier (required if runtime=rknn)
229
+ examples:
230
+ - "rk3566"
231
+ - "rk3588"
232
+
233
+ dataset:
234
+ type: string
235
+ description: Dataset name for zero-shot classification (optional)
236
+ examples:
237
+ - "ImageNet_1k"
238
+ - "TreeOfLife-10M"
239
+
240
+ # If runtime=rknn, rknn_device is required
241
+ if:
242
+ properties:
243
+ runtime:
244
+ const: "rknn"
245
+ then:
246
+ required: ["rknn_device"]
247
+
248
+ # Additional validation rules
249
+ additionalProperties: false
@@ -0,0 +1,166 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://example.com/model-schema.json",
4
+ "title": "Model Info",
5
+ "description": "Schema for Lumen AI model configuration files",
6
+ "type": "object",
7
+ "required": [
8
+ "name",
9
+ "version",
10
+ "description",
11
+ "model_type",
12
+ "embedding_dim",
13
+ "source",
14
+ "runtimes"
15
+ ],
16
+ "properties": {
17
+ "name": {
18
+ "type": "string",
19
+ "description": "Model name identifier, this is also openclip model identifier if openclip is set as source format",
20
+ "minLength": 1,
21
+ "maxLength": 100
22
+ },
23
+ "version": {
24
+ "type": "string",
25
+ "description": "Model version",
26
+ "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
27
+ },
28
+ "description": {
29
+ "type": "string",
30
+ "description": "Model description and purpose",
31
+ "minLength": 1,
32
+ "maxLength": 500
33
+ },
34
+ "model_type": {
35
+ "type": "string",
36
+ "description": "Type of the model"
37
+ },
38
+ "embedding_dim": {
39
+ "type": "integer",
40
+ "description": "Dimension of the embedding space",
41
+ "minimum": 1,
42
+ "maximum": 100000
43
+ },
44
+ "source": {
45
+ "type": "object",
46
+ "required": ["format", "repo_id"],
47
+ "properties": {
48
+ "format": {
49
+ "type": "string",
50
+ "enum": ["huggingface", "openclip", "modelscope", "custom"]
51
+ },
52
+ "repo_id": {
53
+ "type": "string",
54
+ "description": "Repository identifier for model source",
55
+ "minLength": 1
56
+ }
57
+ },
58
+ "additionalProperties": false
59
+ },
60
+ "runtimes": {
61
+ "type": "object",
62
+ "minProperties": 1,
63
+ "patternProperties": {
64
+ "^[a-zA-Z0-9_-]+$": {
65
+ "type": "object",
66
+ "required": ["available"],
67
+ "properties": {
68
+ "available": {
69
+ "type": "boolean"
70
+ },
71
+ "files": {
72
+ "oneOf": [
73
+ {
74
+ "type": "array",
75
+ "items": {
76
+ "type": "string"
77
+ }
78
+ },
79
+ {
80
+ "type": "object",
81
+ "patternProperties": {
82
+ "^[a-zA-Z0-9_-]+$": {
83
+ "type": "array",
84
+ "items": {
85
+ "type": "string"
86
+ }
87
+ }
88
+ },
89
+ "additionalProperties": false
90
+ }
91
+ ]
92
+ },
93
+ "devices": {
94
+ "type": "array",
95
+ "items": {
96
+ "type": "string"
97
+ }
98
+ },
99
+ "requirements": {
100
+ "type": "object",
101
+ "properties": {
102
+ "python": {
103
+ "type": "string"
104
+ },
105
+ "dependencies": {
106
+ "type": "array",
107
+ "items": {
108
+ "type": "string"
109
+ }
110
+ }
111
+ }
112
+ }
113
+ },
114
+ "additionalProperties": false
115
+ }
116
+ },
117
+ "additionalProperties": false
118
+ },
119
+ "datasets": {
120
+ "type": "object",
121
+ "patternProperties": {
122
+ "^[a-zA-Z0-9_-]+$": {
123
+ "type": "object",
124
+ "required": ["labels", "embeddings"],
125
+ "properties": {
126
+ "labels": {
127
+ "type": "string"
128
+ },
129
+ "embeddings": {
130
+ "type": "string"
131
+ }
132
+ },
133
+ "additionalProperties": false
134
+ }
135
+ },
136
+ "additionalProperties": false
137
+ },
138
+ "metadata": {
139
+ "type": "object",
140
+ "properties": {
141
+ "license": {
142
+ "type": "string"
143
+ },
144
+ "author": {
145
+ "type": "string"
146
+ },
147
+ "created_at": {
148
+ "type": "string",
149
+ "format": "date"
150
+ },
151
+ "updated_at": {
152
+ "type": "string",
153
+ "format": "date-time"
154
+ },
155
+ "tags": {
156
+ "type": "array",
157
+ "items": {
158
+ "type": "string"
159
+ }
160
+ }
161
+ },
162
+ "additionalProperties": false
163
+ }
164
+ },
165
+ "additionalProperties": false
166
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "EmbeddingV1",
4
+ "description": "Universal schema for embedding responses across all Lumen services (face, clip, ocr, etc.)",
5
+ "type": "object",
6
+ "properties": {
7
+ "vector": {
8
+ "type": "array",
9
+ "items": {
10
+ "type": "number"
11
+ },
12
+ "minItems": 1,
13
+ "description": "Embedding vector"
14
+ },
15
+ "dim": {
16
+ "type": "integer",
17
+ "minimum": 1,
18
+ "description": "Embedding dimension"
19
+ },
20
+ "model_id": {
21
+ "type": "string",
22
+ "minLength": 1,
23
+ "description": "Model identifier that generated the embedding"
24
+ }
25
+ },
26
+ "required": ["vector", "dim", "model_id"],
27
+ "additionalProperties": false,
28
+ "examples": [
29
+ {
30
+ "vector": [0.1, 0.2, 0.3],
31
+ "dim": 3,
32
+ "model_id": "embedding_model_1"
33
+ }
34
+ ]
35
+ }
@@ -0,0 +1,61 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "FaceV1",
4
+ "description": "Universal schema for face detection and embedding responses across Lumen services",
5
+ "type": "object",
6
+ "properties": {
7
+ "faces": {
8
+ "type": "array",
9
+ "items": {
10
+ "type": "object",
11
+ "properties": {
12
+ "bbox": {
13
+ "type": "array",
14
+ "items": {
15
+ "type": "number",
16
+ "minimum": 0
17
+ },
18
+ "minItems": 4,
19
+ "maxItems": 4,
20
+ "description": "Bounding box coordinates [x1, y1, x2, y2] where (x1, y1) is top-left corner and (x2, y2) is bottom-right corner"
21
+ },
22
+ "confidence": {
23
+ "type": "number",
24
+ "minimum": 0.0,
25
+ "maximum": 1.0,
26
+ "description": "Detection confidence score"
27
+ },
28
+ "landmarks": {
29
+ "type": "array",
30
+ "items": {
31
+ "type": "number"
32
+ },
33
+ "description": "Facial landmark points (optional)"
34
+ },
35
+ "embedding": {
36
+ "type": "array",
37
+ "items": {
38
+ "type": "number"
39
+ },
40
+ "description": "Face embedding vector for recognition/comparison (optional)"
41
+ }
42
+ },
43
+ "required": ["bbox", "confidence"],
44
+ "additionalProperties": false
45
+ },
46
+ "description": "Detected faces with bounding boxes and metadata"
47
+ },
48
+ "count": {
49
+ "type": "integer",
50
+ "minimum": 0,
51
+ "description": "Number of detected faces"
52
+ },
53
+ "model_id": {
54
+ "type": "string",
55
+ "minLength": 1,
56
+ "description": "Model identifier"
57
+ }
58
+ },
59
+ "required": ["faces", "count", "model_id"],
60
+ "additionalProperties": false
61
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "LabelsV1",
4
+ "description": "Classification response schema for Lumen services. Returns ranked labels with confidence scores.",
5
+ "type": "object",
6
+ "properties": {
7
+ "labels": {
8
+ "type": "array",
9
+ "items": {
10
+ "type": "object",
11
+ "properties": {
12
+ "label": {
13
+ "type": "string",
14
+ "description": "The classification label or class name"
15
+ },
16
+ "score": {
17
+ "type": "number",
18
+ "description": "Confidence score for this label"
19
+ }
20
+ },
21
+ "required": ["label", "score"],
22
+ "additionalProperties": false
23
+ },
24
+ "description": "Array of classification results"
25
+ },
26
+ "model_id": {
27
+ "type": "string",
28
+ "minLength": 1,
29
+ "description": "Identifier of the model that generated the classification"
30
+ }
31
+ },
32
+ "required": ["labels", "model_id"],
33
+ "additionalProperties": false,
34
+ "examples": [
35
+ {
36
+ "labels": [
37
+ {
38
+ "label": "cat",
39
+ "score": 0.9
40
+ },
41
+ {
42
+ "label": "dog",
43
+ "score": 0.1
44
+ }
45
+ ],
46
+ "model_id": "embedding_model_1"
47
+ }
48
+ ]
49
+ }
@@ -0,0 +1,133 @@
1
+ Metadata-Version: 2.4
2
+ Name: lumen-resources
3
+ Version: 0.2.0
4
+ Summary: Unified model resource management for Lumen ML services
5
+ Author-email: EdwinZhanCN <support@lumilio.org>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/EdwinZhanCN/Lumen
8
+ Project-URL: Issues, https://github.com/EdwinZhanCN/Lumen/issues
9
+ Requires-Python: >=3.10
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: huggingface_hub>=0.20.0
12
+ Requires-Dist: modelscope>=1.11.0
13
+ Requires-Dist: pydantic>=2.0.0
14
+ Requires-Dist: jsonschema>=4.0.0
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
17
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
18
+ Requires-Dist: black>=23.0.0; extra == "dev"
19
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
20
+ Requires-Dist: datamodel-code-generator[http]>=0.25.0; extra == "dev"
21
+ Requires-Dist: pre-commit>=3.0.0; extra == "dev"
22
+ Provides-Extra: config
23
+ Requires-Dist: pyyaml>=6.0.0; extra == "config"
24
+
25
+ # Lumen Resources
26
+
27
+ Lightweight tooling for shipping Lumen ML services. This package centralizes how models are described, validated, downloaded, and cached so every service (CLIP, face, etc.) follows the same playbook—whether weights live on Hugging Face, ModelScope, or a private registry.
28
+
29
+ ## Why use it?
30
+
31
+ - **Single source of truth** – YAML configs describing deployments, devices, runtimes, and model aliases.
32
+ - **Schema-backed validation** – JSON Schema plus Pydantic to catch errors before runtime.
33
+ - **Cross-platform downloads** – Intelligent routing between Hugging Face and ModelScope with caching/resume support.
34
+ - **CLI + Python API** – Automate in CI or embed in service bootstraps.
35
+ - **Result schemas** – Typed response validators (`EmbeddingV1`, `FaceV1`, `LabelsV1`) for downstream services.
36
+
37
+ ## Installation
38
+
39
+ ```bash
40
+ # project install
41
+ pip install "lumen-resources @ git+https://github.com/EdwinZhanCN/Lumen.git@main#subdirectory=lumen-resources"
42
+
43
+ # dev install
44
+ git clone https://github.com/EdwinZhanCN/Lumen.git
45
+ cd Lumen/lumen-resources
46
+ pip install -e ".[dev,config]"
47
+ ```
48
+
49
+ Optional extras depending on your targets:
50
+
51
+ ```bash
52
+ pip install huggingface_hub
53
+ pip install modelscope
54
+ pip install torch torchvision
55
+ pip install onnxruntime
56
+ ```
57
+
58
+ ## Usage
59
+
60
+ ### CLI
61
+
62
+ ```bash
63
+ # download everything defined in config.yaml
64
+ lumen-resources download config.yaml
65
+
66
+ # strict config validation
67
+ lumen-resources validate config.yaml
68
+
69
+ # validate a model_info.json
70
+ lumen-resources validate-model-info path/to/model_info.json
71
+
72
+ # inspect cache contents (defaults to ~/.lumen/)
73
+ lumen-resources list ~/.lumen/
74
+ ```
75
+
76
+ ### Python API
77
+
78
+ ```python
79
+ from lumen_resources import (
80
+ load_and_validate_config,
81
+ Downloader,
82
+ load_and_validate_model_info,
83
+ EmbeddingV1,
84
+ )
85
+
86
+ config = load_and_validate_config("config.yaml")
87
+ downloader = Downloader(config, verbose=True)
88
+ results = downloader.download_all(force=False)
89
+
90
+ model_info = load_and_validate_model_info("model_info.json")
91
+ ```
92
+
93
+ ## Configuration essentials
94
+
95
+ ```yaml
96
+ metadata:
97
+ region: "other" # or "cn" to prefer ModelScope
98
+ cache_dir: "~/.lumen/models"
99
+
100
+ deployment:
101
+ mode: "single" # or "hub"
102
+ service: "clip"
103
+
104
+ services:
105
+ clip:
106
+ enabled: true
107
+ package: "lumen_clip"
108
+ backend_settings:
109
+ device: "cuda"
110
+ batch_size: 16
111
+ onnx_providers: ["CUDAExecutionProvider", "CPUExecutionProvider"]
112
+ models:
113
+ default:
114
+ model: "ViT-B-32"
115
+ runtime: "torch"
116
+ fp16:
117
+ model: "ViT-B-32"
118
+ runtime: "onnx"
119
+ ```
120
+
121
+ - `metadata.region` decides whether downloads prefer ModelScope or Hugging Face.
122
+ - `backend_settings` lets you declare execution providers, batch sizes, devices, etc.
123
+ - Each entry in `models` becomes a cache namespace (`clip/default`, `clip/fp16`, …).
124
+
125
+ ## Reference
126
+
127
+ - Source: `src/lumen_resources/`
128
+ - `lumen_config.py` – Typed config models
129
+ - `downloader.py` – Platform abstraction + caching
130
+ - `cli.py` – Command entrypoint
131
+ - `result_schemas/` – Response validators
132
+ - Docs: https://doc.lumilio.org
133
+ - Issues & support: open a ticket in the main Lumen monorepo.