modAL 1.4.4.dev14__py3-none-any.whl → 1.4.4.dev16__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.
- modal/_container_entrypoint.py +158 -95
- modal/_functions.py +1 -1
- modal/_image.py +2850 -0
- modal/_runtime/execution_context.py +3 -2
- modal/_runtime/task_lifecycle_manager.py +24 -1
- modal/_runtime/task_lifecycle_manager.pyi +28 -4
- modal/app.py +1 -1
- modal/app.pyi +9 -8
- modal/cli/entry_point.py +2 -0
- modal/cli/skills.py +310 -0
- modal/client.pyi +2 -2
- modal/experimental/__init__.py +6 -6
- modal/functions.pyi +6 -6
- modal/image.py +4 -2853
- modal/image.pyi +10 -1390
- modal/sandbox.py +1 -1
- modal/sandbox.pyi +11 -10
- modal/skills/modal/SKILL.md +86 -0
- {modal-1.4.4.dev14.dist-info → modal-1.4.4.dev16.dist-info}/METADATA +1 -1
- {modal-1.4.4.dev14.dist-info → modal-1.4.4.dev16.dist-info}/RECORD +27 -24
- modal_proto/api_pb2.py +1010 -1010
- modal_proto/api_pb2.pyi +39 -5
- modal_version/__init__.py +1 -1
- {modal-1.4.4.dev14.dist-info → modal-1.4.4.dev16.dist-info}/WHEEL +0 -0
- {modal-1.4.4.dev14.dist-info → modal-1.4.4.dev16.dist-info}/entry_points.txt +0 -0
- {modal-1.4.4.dev14.dist-info → modal-1.4.4.dev16.dist-info}/licenses/LICENSE +0 -0
- {modal-1.4.4.dev14.dist-info → modal-1.4.4.dev16.dist-info}/top_level.txt +0 -0
modal/_container_entrypoint.py
CHANGED
|
@@ -14,7 +14,6 @@ if telemetry_socket:
|
|
|
14
14
|
from ._runtime.telemetry import instrument_imports
|
|
15
15
|
|
|
16
16
|
instrument_imports(telemetry_socket)
|
|
17
|
-
|
|
18
17
|
import asyncio
|
|
19
18
|
import queue
|
|
20
19
|
import signal
|
|
@@ -41,10 +40,11 @@ from ._runtime.container_io_manager import (
|
|
|
41
40
|
ContainerIOManager,
|
|
42
41
|
IOContext,
|
|
43
42
|
)
|
|
44
|
-
from ._runtime.task_lifecycle_manager import UserException
|
|
43
|
+
from ._runtime.task_lifecycle_manager import TaskLifecycleManager, UserException
|
|
45
44
|
|
|
46
45
|
if TYPE_CHECKING:
|
|
47
46
|
import modal._runtime.container_io_manager
|
|
47
|
+
import modal._runtime.task_lifecycle_manager
|
|
48
48
|
import modal._runtime.user_code_imports
|
|
49
49
|
|
|
50
50
|
|
|
@@ -287,12 +287,146 @@ def get_serialized_user_class_and_function(
|
|
|
287
287
|
return ser_usr_cls, ser_fun
|
|
288
288
|
|
|
289
289
|
|
|
290
|
-
def
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
290
|
+
def get_server_service(
|
|
291
|
+
container_args: api_pb2.ContainerArguments, function_def: api_pb2.Function, _client: _Client, client: Client
|
|
292
|
+
) -> Service:
|
|
293
|
+
ser_usr_cls, ser_fun = get_serialized_user_class_and_function(function_def, _client)
|
|
294
|
+
service_base_function_id = container_args.app_layout.function_ids[function_def.function_name]
|
|
295
|
+
service_function_hydration_data = [
|
|
296
|
+
o for o in container_args.app_layout.objects if o.object_id == service_base_function_id
|
|
297
|
+
][0]
|
|
298
|
+
service = import_server_service(
|
|
299
|
+
function_def,
|
|
300
|
+
service_function_hydration_data,
|
|
301
|
+
client,
|
|
302
|
+
ser_usr_cls,
|
|
303
|
+
)
|
|
304
|
+
return service
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
def get_class_service(
|
|
308
|
+
container_args: api_pb2.ContainerArguments, function_def: api_pb2.Function, _client: _Client, client: Client
|
|
309
|
+
) -> Service:
|
|
310
|
+
ser_usr_cls, ser_fun = get_serialized_user_class_and_function(function_def, _client)
|
|
311
|
+
if container_args.serialized_params:
|
|
312
|
+
param_args, param_kwargs = deserialize_params(container_args.serialized_params, function_def, _client)
|
|
313
|
+
else:
|
|
314
|
+
param_args = ()
|
|
315
|
+
param_kwargs = {}
|
|
316
|
+
# this is a bit ugly - match the function and class based on function name to get metadata
|
|
317
|
+
# This metadata is required in order to hydrate the class in case it's not globally
|
|
318
|
+
# decorated (or serialized)
|
|
319
|
+
service_base_function_id = container_args.app_layout.function_ids[function_def.function_name]
|
|
320
|
+
service_function_hydration_data = [
|
|
321
|
+
o for o in container_args.app_layout.objects if o.object_id == service_base_function_id
|
|
322
|
+
][0]
|
|
323
|
+
class_id = container_args.app_layout.class_ids[function_def.function_name.removesuffix(".*")]
|
|
324
|
+
|
|
325
|
+
service = import_class_service(
|
|
326
|
+
function_def,
|
|
327
|
+
service_function_hydration_data,
|
|
328
|
+
class_id,
|
|
329
|
+
client,
|
|
330
|
+
ser_usr_cls,
|
|
331
|
+
param_args,
|
|
332
|
+
param_kwargs,
|
|
333
|
+
)
|
|
334
|
+
return service
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def get_function_service(function_def: api_pb2.Function, _client: _Client) -> Service:
|
|
338
|
+
ser_usr_cls, ser_fun = get_serialized_user_class_and_function(function_def, _client)
|
|
339
|
+
assert ser_usr_cls is None
|
|
340
|
+
service = import_single_function_service(
|
|
341
|
+
function_def,
|
|
342
|
+
ser_fun,
|
|
343
|
+
)
|
|
344
|
+
return service
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def hydrate_function(
|
|
348
|
+
container_args: api_pb2.ContainerArguments,
|
|
349
|
+
task_lifecycle_manager: TaskLifecycleManager,
|
|
350
|
+
function_def: api_pb2.Function,
|
|
351
|
+
_client: _Client,
|
|
352
|
+
client: Client,
|
|
353
|
+
) -> Service:
|
|
294
354
|
active_app: _App
|
|
295
355
|
service: Service
|
|
356
|
+
with task_lifecycle_manager.handle_task_lifecycle_exception():
|
|
357
|
+
with execution_context._import_context():
|
|
358
|
+
if function_def.is_server:
|
|
359
|
+
service = get_server_service(container_args, function_def, _client, client)
|
|
360
|
+
elif function_def.is_class:
|
|
361
|
+
service = get_class_service(container_args, function_def, _client, client)
|
|
362
|
+
else:
|
|
363
|
+
service = get_function_service(function_def, _client)
|
|
364
|
+
|
|
365
|
+
active_app = service.app
|
|
366
|
+
|
|
367
|
+
# Get ids and metadata for objects (primarily functions and classes) on the app
|
|
368
|
+
container_app: RunningApp = running_app_from_layout(container_args.app_id, container_args.app_layout)
|
|
369
|
+
|
|
370
|
+
# Initialize objects on the app.
|
|
371
|
+
# This is basically only functions and classes - anything else is deprecated and will be unsupported soon
|
|
372
|
+
app: App = cast(App, synchronizer._translate_out(active_app))
|
|
373
|
+
app._init_container(client, container_app)
|
|
374
|
+
|
|
375
|
+
# Hydrate all function dependencies.
|
|
376
|
+
# TODO(erikbern): we an remove this once we
|
|
377
|
+
# 1. Enable lazy hydration for all objects
|
|
378
|
+
# 2. Fully deprecate .new() objects
|
|
379
|
+
if service.service_deps is not None: # this is not set for serialized or non-global scope functions
|
|
380
|
+
dep_object_ids: list[str] = [dep.object_id for dep in function_def.object_dependencies]
|
|
381
|
+
if len(service.service_deps) != len(dep_object_ids):
|
|
382
|
+
raise ExecutionError(
|
|
383
|
+
f"Function has {len(service.service_deps)} dependencies"
|
|
384
|
+
f" but container got {len(dep_object_ids)} object ids.\n"
|
|
385
|
+
f"Code deps: {service.service_deps}\n"
|
|
386
|
+
f"Object ids: {dep_object_ids}\n"
|
|
387
|
+
"\n"
|
|
388
|
+
"This can happen if you are defining Modal objects under a conditional statement "
|
|
389
|
+
"that evaluates differently in the local and remote environments."
|
|
390
|
+
)
|
|
391
|
+
for object_id, obj in zip(dep_object_ids, service.service_deps):
|
|
392
|
+
metadata: Message | None = container_app.object_handle_metadata[object_id]
|
|
393
|
+
obj._hydrate(object_id, _client, metadata)
|
|
394
|
+
|
|
395
|
+
return service
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def run_server(container_args: api_pb2.ContainerArguments, client: Client):
|
|
399
|
+
function_def = container_args.function_def
|
|
400
|
+
_client: _Client = cast(_Client, synchronizer._translate_in(client)) # TODO(erikbern): ugly
|
|
401
|
+
task_lifecycle_manager = TaskLifecycleManager(
|
|
402
|
+
container_args.task_id,
|
|
403
|
+
container_args.function_id,
|
|
404
|
+
container_args.function_def,
|
|
405
|
+
container_args.checkpoint_id or None,
|
|
406
|
+
client,
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
service: Service = hydrate_function(container_args, task_lifecycle_manager, function_def, _client, client)
|
|
410
|
+
# Initialize clustered functions.
|
|
411
|
+
if function_def._experimental_group_size > 0:
|
|
412
|
+
initialize_clustered_function(
|
|
413
|
+
client,
|
|
414
|
+
container_args.task_id,
|
|
415
|
+
function_def._experimental_group_size,
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
with UserCodeEventLoop() as event_loop:
|
|
419
|
+
with service.lifecycle_context(
|
|
420
|
+
event_loop,
|
|
421
|
+
task_lifecycle_manager=task_lifecycle_manager,
|
|
422
|
+
):
|
|
423
|
+
call_server(event_loop)
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
def run_function(container_args: api_pb2.ContainerArguments, client: Client):
|
|
427
|
+
# This is a bit weird but we need both the blocking and async versions of ContainerIOManager.
|
|
428
|
+
# At some point, we should fix that by having built-in support for running "user code"
|
|
429
|
+
container_io_manager: Any = ContainerIOManager(container_args, client)
|
|
296
430
|
function_def = container_args.function_def
|
|
297
431
|
# The worker sets this flag to "1" for snapshot and restore tasks. Otherwise, this flag is unset,
|
|
298
432
|
# in which case snapshots should be disabled.
|
|
@@ -306,92 +440,17 @@ def main(container_args: api_pb2.ContainerArguments, client: Client):
|
|
|
306
440
|
container_io_manager.hello()
|
|
307
441
|
|
|
308
442
|
with container_io_manager.heartbeats(is_snapshotting_function), UserCodeEventLoop() as event_loop:
|
|
309
|
-
# If this is a serialized function, fetch the definition from the server
|
|
310
|
-
ser_usr_cls, ser_fun = get_serialized_user_class_and_function(function_def, _client)
|
|
311
|
-
|
|
312
443
|
# Initialize the function, importing user code.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
service_function_hydration_data = [
|
|
324
|
-
o for o in container_args.app_layout.objects if o.object_id == service_base_function_id
|
|
325
|
-
][0]
|
|
326
|
-
service = import_server_service(
|
|
327
|
-
function_def,
|
|
328
|
-
service_function_hydration_data,
|
|
329
|
-
client,
|
|
330
|
-
ser_usr_cls,
|
|
331
|
-
)
|
|
332
|
-
elif function_def.is_class:
|
|
333
|
-
# this is a bit ugly - match the function and class based on function name to get metadata
|
|
334
|
-
# This metadata is required in order to hydrate the class in case it's not globally
|
|
335
|
-
# decorated (or serialized)
|
|
336
|
-
service_base_function_id = container_args.app_layout.function_ids[function_def.function_name]
|
|
337
|
-
service_function_hydration_data = [
|
|
338
|
-
o for o in container_args.app_layout.objects if o.object_id == service_base_function_id
|
|
339
|
-
][0]
|
|
340
|
-
class_id = container_args.app_layout.class_ids[function_def.function_name.removesuffix(".*")]
|
|
341
|
-
|
|
342
|
-
service = import_class_service(
|
|
343
|
-
function_def,
|
|
344
|
-
service_function_hydration_data,
|
|
345
|
-
class_id,
|
|
346
|
-
client,
|
|
347
|
-
ser_usr_cls,
|
|
348
|
-
param_args,
|
|
349
|
-
param_kwargs,
|
|
350
|
-
)
|
|
351
|
-
else:
|
|
352
|
-
assert ser_usr_cls is None
|
|
353
|
-
service = import_single_function_service(
|
|
354
|
-
function_def,
|
|
355
|
-
ser_fun,
|
|
356
|
-
)
|
|
357
|
-
|
|
358
|
-
active_app = service.app
|
|
359
|
-
|
|
360
|
-
if function_def.pty_info.pty_type == api_pb2.PTYInfo.PTY_TYPE_SHELL:
|
|
361
|
-
# Concurrency and batching doesn't apply for `modal shell`.
|
|
362
|
-
batch_max_size = 0
|
|
363
|
-
batch_wait_ms = 0
|
|
364
|
-
else:
|
|
365
|
-
batch_max_size = function_def.batch_max_size or 0
|
|
366
|
-
batch_wait_ms = function_def.batch_linger_ms or 0
|
|
367
|
-
|
|
368
|
-
# Get ids and metadata for objects (primarily functions and classes) on the app
|
|
369
|
-
container_app: RunningApp = running_app_from_layout(container_args.app_id, container_args.app_layout)
|
|
370
|
-
|
|
371
|
-
# Initialize objects on the app.
|
|
372
|
-
# This is basically only functions and classes - anything else is deprecated and will be unsupported soon
|
|
373
|
-
app: App = cast(App, synchronizer._translate_out(active_app))
|
|
374
|
-
app._init_container(client, container_app)
|
|
375
|
-
|
|
376
|
-
# Hydrate all function dependencies.
|
|
377
|
-
# TODO(erikbern): we an remove this once we
|
|
378
|
-
# 1. Enable lazy hydration for all objects
|
|
379
|
-
# 2. Fully deprecate .new() objects
|
|
380
|
-
if service.service_deps is not None: # this is not set for serialized or non-global scope functions
|
|
381
|
-
dep_object_ids: list[str] = [dep.object_id for dep in function_def.object_dependencies]
|
|
382
|
-
if len(service.service_deps) != len(dep_object_ids):
|
|
383
|
-
raise ExecutionError(
|
|
384
|
-
f"Function has {len(service.service_deps)} dependencies"
|
|
385
|
-
f" but container got {len(dep_object_ids)} object ids.\n"
|
|
386
|
-
f"Code deps: {service.service_deps}\n"
|
|
387
|
-
f"Object ids: {dep_object_ids}\n"
|
|
388
|
-
"\n"
|
|
389
|
-
"This can happen if you are defining Modal objects under a conditional statement "
|
|
390
|
-
"that evaluates differently in the local and remote environments."
|
|
391
|
-
)
|
|
392
|
-
for object_id, obj in zip(dep_object_ids, service.service_deps):
|
|
393
|
-
metadata: Message | None = container_app.object_handle_metadata[object_id]
|
|
394
|
-
obj._hydrate(object_id, _client, metadata)
|
|
444
|
+
service: Service = hydrate_function(
|
|
445
|
+
container_args, container_io_manager.get_task_lifecycle_manager(), function_def, _client, client
|
|
446
|
+
)
|
|
447
|
+
if function_def.pty_info.pty_type == api_pb2.PTYInfo.PTY_TYPE_SHELL:
|
|
448
|
+
# Concurrency and batching doesn't apply for `modal shell`.
|
|
449
|
+
batch_max_size = 0
|
|
450
|
+
batch_wait_ms = 0
|
|
451
|
+
else:
|
|
452
|
+
batch_max_size = function_def.batch_max_size or 0
|
|
453
|
+
batch_wait_ms = function_def.batch_linger_ms or 0
|
|
395
454
|
|
|
396
455
|
# Initialize clustered functions.
|
|
397
456
|
if function_def._experimental_group_size > 0:
|
|
@@ -407,10 +466,14 @@ def main(container_args: api_pb2.ContainerArguments, client: Client):
|
|
|
407
466
|
) as finalized_functions:
|
|
408
467
|
# This context managers handles pre/post snapshot lifecycle of the user code,
|
|
409
468
|
# finalized functions, ASGI/WSGI lifespan, and volume commit.
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
469
|
+
call_function(event_loop, container_io_manager, finalized_functions, batch_max_size, batch_wait_ms)
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def main(container_args: api_pb2.ContainerArguments, client: Client):
|
|
473
|
+
if container_args.function_def.is_server:
|
|
474
|
+
run_server(container_args, client)
|
|
475
|
+
else:
|
|
476
|
+
run_function(container_args, client)
|
|
414
477
|
|
|
415
478
|
|
|
416
479
|
if __name__ == "__main__":
|
modal/_functions.py
CHANGED
|
@@ -19,6 +19,7 @@ from modal_proto import api_pb2
|
|
|
19
19
|
from modal_proto.modal_api_grpc import ModalClientModal
|
|
20
20
|
|
|
21
21
|
from ._function_variants import _FunctionOptions, _make_function_variant
|
|
22
|
+
from ._image import _Image
|
|
22
23
|
from ._load_context import LoadContext
|
|
23
24
|
from ._object import _Object, live_method, live_method_gen
|
|
24
25
|
from ._output.pty import get_pty_info
|
|
@@ -65,7 +66,6 @@ from .exception import (
|
|
|
65
66
|
NotFoundError,
|
|
66
67
|
OutputExpiredError,
|
|
67
68
|
)
|
|
68
|
-
from .image import _Image
|
|
69
69
|
from .mount import _get_client_mount, _Mount
|
|
70
70
|
from .network_file_system import _NetworkFileSystem, network_file_system_mount_protos
|
|
71
71
|
from .output import OutputManager
|