nos.server
nos.server¶
Docker Runtime¶
The docker runtime provides the docker-py
interface to run containerized inference workloads using Docker. It allows starting and stopping containers, getting container information, and running the containers programmatically with HW support for accelerators like GPUs, ASICs etc.
nos.server._docker.DeviceRequest
dataclass
¶
Device request mappings for docker-py.
For the given key, we map to the corresponding
docker.types.DeviceRequest
or docker.types.Device
object.
This makes it easy to add new devices in the future.
Source code in nos/server/_docker.py
get
classmethod
¶
nos.server._docker.DockerRuntime
dataclass
¶
Docker runtime for running containerized inference workloads.
Source code in nos/server/_docker.py
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 |
|
__init__ ¶
get
classmethod
¶
get() -> DockerRuntime
list
classmethod
¶
start ¶
start(image: str, command: Optional[Union[str, List[str]]] = None, name: str = None, device: Optional[str] = None, **kwargs: Any) -> Container
Start docker container.
Parameters:
-
**kwargs
(Any
, default:{}
) –See https://docker-py.readthedocs.io/en/stable/containers.html#docker.models.containers.ContainerCollection.run
-
ports
(Optional[Dict[int, int]]
) –Port mapping. Defaults to None.
-
environment
(Optional[Dict[str, str]]
) –Environment variables. Defaults to None.
-
volumes
(Optional[Dict[str, str]]
) –Volume mapping. Defaults to None.
-
shm_size
(Optional[int]
) –Shared memory size. Defaults to None.
-
detach
(bool
) –Whether to run the container in detached mode. Defaults to True.
-
remove
(bool
) –Whether to remove the container when it exits. Defaults to True.
-
device
(bool
, default:None
) –Device to request (i.e. gpu, inf2). Defaults to None (i.e. cpu).
Note (Non-standard arguments): gpu (bool): Whether to start the container with GPU support.
Source code in nos/server/_docker.py
stop ¶
Stop docker container.
Source code in nos/server/_docker.py
get_container_id ¶
get_container ¶
get_container_status ¶
get_container_logs ¶
Get container logs.
Source code in nos/server/_docker.py
InferenceServiceRuntime¶
nos.server._runtime.InferenceServiceRuntime ¶
Inference service runtime.
This class is responsible for handling the lifecycle of the inference service docker runtime.
Attributes:
-
configs
(InferenceServiceConfig
) –Inference service configuration.
Source code in nos/server/_runtime.py
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 |
|
__init__ ¶
Initialize the inference runtime.
Parameters:
-
runtime
(str
, default:'cpu'
) –Inference runtime. Defaults to "cpu".
-
name
(str
, default:None
) –Inference runtime name. Defaults to "nos-inference-service".
Source code in nos/server/_runtime.py
detect
staticmethod
¶
Auto-detect inference runtime.
devices
staticmethod
¶
Auto-detect devices to use.
Source code in nos/server/_runtime.py
list
staticmethod
¶
List running docker containers.
Source code in nos/server/_runtime.py
supported_runtimes
classmethod
¶
start ¶
Start the inference runtime.
Parameters:
-
**kwargs
(Any
, default:{}
) –Additional keyword-arguments to pass to
DockerRuntime.start
.
Source code in nos/server/_runtime.py
InferenceService¶
The InferenceService
along with the InferenceServiceImpl
gRPC service implementation provides a fully wrapped inference service via gRPC/HTTP2. The InferenceServiceImpl
wraps the relevant API services such as ListModels()
, GetModelInfo()
and crucially Run()
and executes the inference request via the InferenceService
class. The InferenceService
class manages models via the ModelManager
, and sets up the necessary execution backend via RayExecutor
. In addition to this, it is also responsible for managing shared memory regions (if requested) for high-performance inference running locally in a single machine.
nos.server._service.ModelHandle
dataclass
¶
Model handles for distributed model execution.
Usage
# Initialize a model handle
>> model = ModelHandle(spec, num_replicas=1)
# Call the task immediately
>> response = model(**model_inputs)
# Call a method on the model handle
>> response = model.process_images(**model_inputs)
# Submit a task to the model handle,
# this will add results to the queue
>> model.submit(**model_inputs)
# Fetch the next result from the queue
>> response = model.get()
# Submit a task to a specific model handle method
>> model.submit(**model_inputs, _method="process_images")
# Submit a task to the model handle,
# this will add results to the queue
>> model_handle.submit(**model_inputs)
# Fetch the next result from the queue
>> response = model_handle.get()
# Cleanup model resources
>> model_handle.cleanup()
Source code in nos/managers/model.py
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 |
|
deployment
class-attribute
instance-attribute
¶
Number of replicas.
__post_init__ ¶
Initialize the actor handles.
Source code in nos/managers/model.py
__call__ ¶
Call the task immediately.
Parameters:
-
*args
(Any
, default:()
) –Model arguments.
-
**kwargs
(Any
, default:{}
) –Model keyword arguments (except for special
_method
keyword that is used to call different class methods).
Returns: Model response.
Source code in nos/managers/model.py
scale ¶
scale(num_replicas: Union[int, str] = 1) -> ModelHandle
Scale the model handle to a new number of replicas.
Parameters:
-
num_replicas
(int or str
, default:1
) –Number of replicas, or set to "auto" to automatically scale the model to the number of GPUs available.
Source code in nos/managers/model.py
submit ¶
Submit a task to the actor pool.
Note (spillai): Caveats for .submit()
with custom methods:
ModelHandles have a single result queue that add
results asynchronously on task completion. Calling submit()
with different methods interchangably will result in
the results queue being populated with results from
different methods. In other words, it is advised to
use submit()
with the same method for a given model
and then use get()
to fetch all the results, before
calling submit()
with a different method.
Parameters:
-
*args
(Any
, default:()
) –Model arguments.
-
**kwargs
(Any
, default:{}
) –Model keyword arguments (except for special
_method
keyword that is used to call different class methods).
Returns:
-
ObjectRef
–ray.ObjectRef: Ray object reference as a string.
Source code in nos/managers/model.py
cleanup ¶
get ¶
async_get
async
¶
nos.server._service.InferenceServiceImpl ¶
Experimental gRPC-based inference service.
This service is used to serve models over gRPC.
Refer to the bring-your-own-schema section: https://docs.ray.io/en/master/serve/direct-ingress.html?highlight=grpc#bring-your-own-schema
Source code in nos/server/_service.py
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 |
|
Ping
async
¶
GetServiceInfo ¶
Get information on the service.
Source code in nos/server/_service.py
ListModels ¶
List all models.
Source code in nos/server/_service.py
GetModelCatalog ¶
Get the model catalog.
Source code in nos/server/_service.py
GetModelInfo ¶
Get model information.
Source code in nos/server/_service.py
LoadModel ¶
Load / scale the model to the specified number of replicas.
Source code in nos/server/_service.py
RegisterSystemSharedMemory ¶
Register system shared memory under a specific namespace <client_id>/<object_id>
.
Source code in nos/server/_service.py
UnregisterSystemSharedMemory ¶
Unregister system shared memory for specific namespace <client_id>/<object_id>
.
Source code in nos/server/_service.py
UploadFile ¶
Upload a file.
Source code in nos/server/_service.py
DeleteFile ¶
Delete a file by its file-identifier.
Source code in nos/server/_service.py
Run
async
¶
Main model prediction interface.
Source code in nos/server/_service.py
Stream
async
¶
Main streaming model prediction interface.
Source code in nos/server/_service.py
nos.server._service.async_serve ¶
async_serve(address: str = DEFAULT_GRPC_ADDRESS, max_workers: int = GRPC_MAX_WORKER_THREADS, wait_for_termination: bool = True, catalog: str = None)
Start the gRPC server.