modal 1.7.0.dev0__py3-none-any.whl → 1.7.0.dev2__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/__init__.py +0 -2
- modal/_environments.py +10 -10
- modal/_functions.py +16 -99
- modal/_image.py +26 -4
- modal/_logs.py +2 -2
- modal/_logs_manager.py +12 -12
- modal/_metrics.py +6 -6
- modal/_object.py +13 -0
- modal/_resolver.py +6 -0
- modal/_runtime/asgi.py +1 -1
- modal/_serialization.py +1 -1
- modal/_server.py +6 -7
- modal/_utils/async_utils.py +5 -5
- modal/_utils/grpc_utils.py +2 -9
- modal/_utils/http_utils.py +2 -1
- modal/_utils/mount_utils.py +2 -18
- modal/_utils/time_utils.py +14 -14
- modal/_workspace.py +100 -22
- modal/app.py +6 -14
- modal/app.pyi +0 -17
- modal/cli/_audit_logs.py +2 -2
- modal/cli/_download.py +1 -2
- modal/cli/_logs.py +4 -4
- modal/cli/_stats.py +7 -7
- modal/cli/app.py +5 -5
- modal/cli/container.py +6 -6
- modal/cli/entry_point.py +0 -2
- modal/cli/function.py +9 -9
- modal/cli/server.py +8 -8
- modal/cli/shell.py +0 -1
- modal/cli/utils.py +2 -2
- modal/cli/workspace.py +193 -21
- modal/client.pyi +2 -2
- modal/container_process.py +1 -1
- modal/exception.py +4 -0
- modal/experimental/__init__.py +9 -18
- modal/experimental/stream.py +5 -5
- modal/functions.pyi +0 -4
- modal/image.py +2 -1
- modal/image.pyi +39 -5
- modal/io_streams.py +9 -9
- modal/io_streams.pyi +11 -4
- modal/mount.py +5 -1
- modal/object.pyi +19 -2
- modal/parallel_map.py +64 -150
- modal/parallel_map.pyi +5 -22
- modal/retries.py +1 -0
- modal/runner.py +6 -7
- modal/sandbox/_common.py +26 -8
- modal/sandbox/_impl_persistent.py +277 -138
- modal/sandbox/_impl_v1.py +69 -47
- modal/sandbox/_impl_v2.py +69 -43
- modal/sandbox/_sandbox.py +103 -229
- modal/sandbox/_sidecar.py +1 -1
- modal/sandbox/_task_command_router_client.py +28 -7
- modal/sandbox/sandbox.pyi +41 -302
- modal/secret.py +2 -2
- modal/token_flow.py +5 -1
- modal/types.py +49 -26
- modal/workspace.pyi +129 -15
- {modal-1.7.0.dev0.dist-info → modal-1.7.0.dev2.dist-info}/METADATA +1 -1
- {modal-1.7.0.dev0.dist-info → modal-1.7.0.dev2.dist-info}/RECORD +76 -79
- modal_docs/gen_reference_docs.py +1 -1
- modal_proto/api_grpc.py +160 -0
- modal_proto/api_pb2.py +773 -727
- modal_proto/api_pb2.pyi +478 -9
- modal_proto/api_pb2_grpc.py +331 -0
- modal_proto/api_pb2_grpc.pyi +102 -0
- modal_proto/modal_api_grpc.py +10 -0
- modal_proto/task_command_router_pb2.py +73 -69
- modal_proto/task_command_router_pb2.pyi +49 -2
- modal_version/__init__.py +1 -1
- modal/cli/network_file_system.py +0 -227
- modal/network_file_system.py +0 -369
- modal/network_file_system.pyi +0 -484
- {modal-1.7.0.dev0.dist-info → modal-1.7.0.dev2.dist-info}/WHEEL +0 -0
- {modal-1.7.0.dev0.dist-info → modal-1.7.0.dev2.dist-info}/entry_points.txt +0 -0
- {modal-1.7.0.dev0.dist-info → modal-1.7.0.dev2.dist-info}/licenses/LICENSE +0 -0
- {modal-1.7.0.dev0.dist-info → modal-1.7.0.dev2.dist-info}/top_level.txt +0 -0
modal/__init__.py
CHANGED
|
@@ -24,7 +24,6 @@ try:
|
|
|
24
24
|
from .file_pattern_matcher import FilePatternMatcher
|
|
25
25
|
from .functions import Function, FunctionCall
|
|
26
26
|
from .image import Image
|
|
27
|
-
from .network_file_system import NetworkFileSystem
|
|
28
27
|
from .output import enable_output
|
|
29
28
|
from .partial_function import (
|
|
30
29
|
asgi_app,
|
|
@@ -74,7 +73,6 @@ __all__ = [
|
|
|
74
73
|
"Function",
|
|
75
74
|
"FunctionCall",
|
|
76
75
|
"Image",
|
|
77
|
-
"NetworkFileSystem",
|
|
78
76
|
"OutboundPolicy",
|
|
79
77
|
"OutboundRoute",
|
|
80
78
|
"Period",
|
modal/_environments.py
CHANGED
|
@@ -3,7 +3,7 @@ import asyncio
|
|
|
3
3
|
import builtins
|
|
4
4
|
from collections.abc import Iterable, Mapping
|
|
5
5
|
from dataclasses import dataclass
|
|
6
|
-
from datetime import
|
|
6
|
+
from datetime import UTC, datetime
|
|
7
7
|
from typing import TYPE_CHECKING, Any, Literal
|
|
8
8
|
|
|
9
9
|
from google.protobuf.empty_pb2 import Empty
|
|
@@ -530,16 +530,16 @@ class _EnvironmentBillingManager:
|
|
|
530
530
|
tag_names = []
|
|
531
531
|
|
|
532
532
|
if end is None:
|
|
533
|
-
end = datetime.now(
|
|
533
|
+
end = datetime.now(UTC)
|
|
534
534
|
|
|
535
535
|
if start.tzinfo is None:
|
|
536
|
-
start = start.replace(tzinfo=
|
|
537
|
-
elif start.tzinfo !=
|
|
536
|
+
start = start.replace(tzinfo=UTC)
|
|
537
|
+
elif start.tzinfo != UTC:
|
|
538
538
|
raise InvalidError("Timezone-aware 'start' parameter must be in UTC.")
|
|
539
539
|
|
|
540
540
|
if end.tzinfo is None:
|
|
541
|
-
end = end.replace(tzinfo=
|
|
542
|
-
elif end.tzinfo !=
|
|
541
|
+
end = end.replace(tzinfo=UTC)
|
|
542
|
+
elif end.tzinfo != UTC:
|
|
543
543
|
raise InvalidError("Timezone-aware 'end' parameter must be in UTC.")
|
|
544
544
|
|
|
545
545
|
if not self._environment._is_hydrated:
|
|
@@ -592,7 +592,7 @@ class _EnvironmentBillingManager:
|
|
|
592
592
|
"""
|
|
593
593
|
|
|
594
594
|
if cycle is None:
|
|
595
|
-
cycle = datetime.now(
|
|
595
|
+
cycle = datetime.now(UTC).replace(
|
|
596
596
|
day=1,
|
|
597
597
|
hour=0,
|
|
598
598
|
minute=0,
|
|
@@ -603,14 +603,14 @@ class _EnvironmentBillingManager:
|
|
|
603
603
|
cycle = parse_billing_cycle(cycle)
|
|
604
604
|
|
|
605
605
|
if cycle.tzinfo is None:
|
|
606
|
-
cycle = cycle.replace(tzinfo=
|
|
607
|
-
elif cycle.tzinfo !=
|
|
606
|
+
cycle = cycle.replace(tzinfo=UTC)
|
|
607
|
+
elif cycle.tzinfo != UTC:
|
|
608
608
|
raise InvalidError("Timezone-aware 'cycle' parameter must be in UTC.")
|
|
609
609
|
|
|
610
610
|
if not is_utc_month_aligned(cycle):
|
|
611
611
|
raise InvalidError("Provided 'cycle' parameter must be the first of a month.")
|
|
612
612
|
|
|
613
|
-
if cycle > datetime.now(
|
|
613
|
+
if cycle > datetime.now(UTC):
|
|
614
614
|
raise InvalidError("Provided 'cycle' parameter cannot be in the future.")
|
|
615
615
|
|
|
616
616
|
if not self._environment._is_hydrated:
|
modal/_functions.py
CHANGED
|
@@ -9,7 +9,7 @@ import warnings
|
|
|
9
9
|
from collections import OrderedDict
|
|
10
10
|
from collections.abc import AsyncGenerator, Callable, Collection, Sequence
|
|
11
11
|
from dataclasses import dataclass
|
|
12
|
-
from datetime import datetime, timedelta
|
|
12
|
+
from datetime import UTC, datetime, timedelta
|
|
13
13
|
from pathlib import PurePosixPath
|
|
14
14
|
from typing import TYPE_CHECKING, Any, Literal
|
|
15
15
|
|
|
@@ -68,7 +68,7 @@ from ._utils.function_utils import (
|
|
|
68
68
|
validate_target_concurrency,
|
|
69
69
|
)
|
|
70
70
|
from ._utils.grpc_utils import Retry, RetryWarningMessage, is_class_function_lookup_error
|
|
71
|
-
from ._utils.mount_utils import
|
|
71
|
+
from ._utils.mount_utils import validate_volumes, validate_volumes_by_object_id
|
|
72
72
|
from .call_graph import InputInfo, _reconstruct_call_graph
|
|
73
73
|
from .client import _Client
|
|
74
74
|
from .cloud_bucket_mount import _CloudBucketMount, cloud_bucket_mounts_to_proto
|
|
@@ -80,7 +80,6 @@ from .exception import (
|
|
|
80
80
|
OutputExpiredError,
|
|
81
81
|
)
|
|
82
82
|
from .mount import _get_client_mount, _Mount
|
|
83
|
-
from .network_file_system import _NetworkFileSystem, network_file_system_mount_protos
|
|
84
83
|
from .output import OutputManager
|
|
85
84
|
from .parallel_map import (
|
|
86
85
|
_experimental_spawn_map_async,
|
|
@@ -99,7 +98,7 @@ from .parallel_map import (
|
|
|
99
98
|
_SynchronizedQueue,
|
|
100
99
|
)
|
|
101
100
|
from .proxy import _Proxy
|
|
102
|
-
from .retries import Retries, RetryManager
|
|
101
|
+
from .retries import MAX_INTERNAL_FAILURE_COUNT, Retries, RetryManager
|
|
103
102
|
from .schedule import Schedule
|
|
104
103
|
from .secret import _Secret
|
|
105
104
|
from .types import (
|
|
@@ -118,7 +117,6 @@ if TYPE_CHECKING:
|
|
|
118
117
|
import modal.cls
|
|
119
118
|
import modal.functions
|
|
120
119
|
|
|
121
|
-
MAX_INTERNAL_FAILURE_COUNT = 8
|
|
122
120
|
_OBSERVABILITY_ONLY_APIS = (
|
|
123
121
|
".logs",
|
|
124
122
|
".metrics",
|
|
@@ -135,17 +133,6 @@ TERMINAL_STATUSES = (
|
|
|
135
133
|
)
|
|
136
134
|
|
|
137
135
|
|
|
138
|
-
@dataclasses.dataclass
|
|
139
|
-
class _RetryContext:
|
|
140
|
-
function_call_invocation_type: "api_pb2.FunctionCallInvocationType.ValueType"
|
|
141
|
-
retry_policy: api_pb2.FunctionRetryPolicy
|
|
142
|
-
function_call_jwt: str
|
|
143
|
-
input_jwt: str
|
|
144
|
-
input_id: str
|
|
145
|
-
item: api_pb2.FunctionPutInputsItem
|
|
146
|
-
sync_client_retries_enabled: bool
|
|
147
|
-
|
|
148
|
-
|
|
149
136
|
class _Invocation:
|
|
150
137
|
"""Internal client representation of a single-input call to a Modal Function or Generator"""
|
|
151
138
|
|
|
@@ -156,12 +143,10 @@ class _Invocation:
|
|
|
156
143
|
stub: ModalClientModal,
|
|
157
144
|
function_call_id: str,
|
|
158
145
|
client: _Client,
|
|
159
|
-
retry_context: _RetryContext | None = None,
|
|
160
146
|
):
|
|
161
147
|
self.stub = stub
|
|
162
148
|
self.client = client # Used by the deserializer.
|
|
163
149
|
self.function_call_id = function_call_id # TODO: remove and use only input_id
|
|
164
|
-
self._retry_context = retry_context
|
|
165
150
|
|
|
166
151
|
@staticmethod
|
|
167
152
|
async def create(
|
|
@@ -215,17 +200,7 @@ class _Invocation:
|
|
|
215
200
|
function_call_id = response.function_call_id
|
|
216
201
|
if response.pipelined_inputs:
|
|
217
202
|
assert len(response.pipelined_inputs) == 1
|
|
218
|
-
|
|
219
|
-
retry_context = _RetryContext(
|
|
220
|
-
function_call_invocation_type=function_call_invocation_type,
|
|
221
|
-
retry_policy=response.retry_policy,
|
|
222
|
-
function_call_jwt=response.function_call_jwt,
|
|
223
|
-
input_jwt=input.input_jwt,
|
|
224
|
-
input_id=input.input_id,
|
|
225
|
-
item=item,
|
|
226
|
-
sync_client_retries_enabled=response.sync_client_retries_enabled,
|
|
227
|
-
)
|
|
228
|
-
return _Invocation(stub, function_call_id, client, retry_context)
|
|
203
|
+
return _Invocation(stub, function_call_id, client)
|
|
229
204
|
|
|
230
205
|
request_put = api_pb2.FunctionPutInputsRequest(
|
|
231
206
|
function_id=function_id, inputs=[item], function_call_id=function_call_id
|
|
@@ -234,24 +209,13 @@ class _Invocation:
|
|
|
234
209
|
processed_inputs = inputs_response.inputs
|
|
235
210
|
if not processed_inputs:
|
|
236
211
|
raise Exception("Could not create function call - the input queue seems to be full")
|
|
237
|
-
|
|
238
|
-
retry_context = _RetryContext(
|
|
239
|
-
function_call_invocation_type=function_call_invocation_type,
|
|
240
|
-
retry_policy=response.retry_policy,
|
|
241
|
-
function_call_jwt=response.function_call_jwt,
|
|
242
|
-
input_jwt=input.input_jwt,
|
|
243
|
-
input_id=input.input_id,
|
|
244
|
-
item=item,
|
|
245
|
-
sync_client_retries_enabled=response.sync_client_retries_enabled,
|
|
246
|
-
)
|
|
247
|
-
return _Invocation(stub, function_call_id, client, retry_context)
|
|
212
|
+
return _Invocation(stub, function_call_id, client)
|
|
248
213
|
|
|
249
214
|
async def pop_function_call_outputs(
|
|
250
215
|
self,
|
|
251
216
|
index: int = 0,
|
|
252
217
|
timeout: float | None = None,
|
|
253
218
|
clear_on_success: bool = False,
|
|
254
|
-
input_jwts: list[str] | None = None,
|
|
255
219
|
) -> api_pb2.FunctionGetOutputsResponse:
|
|
256
220
|
t0 = time.time()
|
|
257
221
|
if timeout is None:
|
|
@@ -268,7 +232,6 @@ class _Invocation:
|
|
|
268
232
|
last_entry_id="0-0",
|
|
269
233
|
clear_on_success=clear_on_success,
|
|
270
234
|
requested_at=time.time(),
|
|
271
|
-
input_jwts=input_jwts,
|
|
272
235
|
start_idx=index,
|
|
273
236
|
end_idx=index,
|
|
274
237
|
)
|
|
@@ -287,58 +250,20 @@ class _Invocation:
|
|
|
287
250
|
# return the last response to check for state of num_unfinished_inputs
|
|
288
251
|
return response
|
|
289
252
|
|
|
290
|
-
async def
|
|
291
|
-
ctx = self._retry_context
|
|
292
|
-
if not ctx:
|
|
293
|
-
raise ValueError("Cannot retry input when _retry_context is empty.")
|
|
294
|
-
|
|
295
|
-
item = api_pb2.FunctionRetryInputsItem(input_jwt=ctx.input_jwt, input=ctx.item.input)
|
|
296
|
-
request = api_pb2.FunctionRetryInputsRequest(function_call_jwt=ctx.function_call_jwt, inputs=[item])
|
|
297
|
-
await self.stub.FunctionRetryInputs(request)
|
|
298
|
-
|
|
299
|
-
async def _get_single_output(self, expected_jwt: str | None = None) -> api_pb2.FunctionGetOutputsItem:
|
|
253
|
+
async def _get_single_output(self) -> api_pb2.FunctionGetOutputsItem:
|
|
300
254
|
# waits indefinitely for a single result for the function, and clear the outputs buffer after
|
|
301
255
|
item: api_pb2.FunctionGetOutputsItem = (
|
|
302
256
|
await self.pop_function_call_outputs(
|
|
303
257
|
index=0,
|
|
304
258
|
timeout=None,
|
|
305
259
|
clear_on_success=True,
|
|
306
|
-
input_jwts=[expected_jwt] if expected_jwt else None,
|
|
307
260
|
)
|
|
308
261
|
).outputs[0]
|
|
309
262
|
return item
|
|
310
263
|
|
|
311
264
|
async def run_function(self) -> Any:
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
not ctx
|
|
316
|
-
or not ctx.retry_policy
|
|
317
|
-
or ctx.retry_policy.retries == 0
|
|
318
|
-
or ctx.function_call_invocation_type != api_pb2.FUNCTION_CALL_INVOCATION_TYPE_SYNC
|
|
319
|
-
or not ctx.sync_client_retries_enabled
|
|
320
|
-
):
|
|
321
|
-
item = await self._get_single_output()
|
|
322
|
-
return await _process_result(item.result, item.data_format, self.stub, self.client)
|
|
323
|
-
|
|
324
|
-
# User errors including timeouts are managed by the user specified retry policy.
|
|
325
|
-
user_retry_manager = RetryManager(ctx.retry_policy)
|
|
326
|
-
|
|
327
|
-
while True:
|
|
328
|
-
item = await self._get_single_output(ctx.input_jwt)
|
|
329
|
-
if item.result.status in TERMINAL_STATUSES:
|
|
330
|
-
return await _process_result(item.result, item.data_format, self.stub, self.client)
|
|
331
|
-
|
|
332
|
-
if item.result.status != api_pb2.GenericResult.GENERIC_STATUS_INTERNAL_FAILURE:
|
|
333
|
-
# non-internal failures get a delay before retrying
|
|
334
|
-
delay_ms = user_retry_manager.get_delay_ms()
|
|
335
|
-
if delay_ms is None:
|
|
336
|
-
# no more retries, this should raise an error when the non-success status is converted
|
|
337
|
-
# to an exception:
|
|
338
|
-
return await _process_result(item.result, item.data_format, self.stub, self.client)
|
|
339
|
-
await asyncio.sleep(delay_ms / 1000)
|
|
340
|
-
|
|
341
|
-
await self._retry_input()
|
|
265
|
+
item = await self._get_single_output()
|
|
266
|
+
return await _process_result(item.result, item.data_format, self.stub, self.client)
|
|
342
267
|
|
|
343
268
|
async def poll_function(self, timeout: float | None = None, *, index: int = 0):
|
|
344
269
|
"""Waits up to timeout for a result from a function.
|
|
@@ -585,7 +510,6 @@ class _FunctionSpec:
|
|
|
585
510
|
image: _Image | None
|
|
586
511
|
mounts: Sequence[_Mount]
|
|
587
512
|
secrets: Collection[_Secret]
|
|
588
|
-
network_file_systems: dict[str | PurePosixPath, _NetworkFileSystem]
|
|
589
513
|
volumes: dict[str | PurePosixPath, _Volume | _CloudBucketMount]
|
|
590
514
|
# TODO(colin, was irfansharif): Somehow assert that it's the first kind, in sandboxes
|
|
591
515
|
gpus: str | list[str] | None
|
|
@@ -704,8 +628,6 @@ class _Function(typing.Generic[P, ReturnType, OriginalReturnType], _Object, type
|
|
|
704
628
|
schedule: Schedule | None = None,
|
|
705
629
|
is_generator: bool = False,
|
|
706
630
|
gpu: str | list[str] | None = None,
|
|
707
|
-
# TODO: maybe break this out into a separate decorator for notebooks.
|
|
708
|
-
network_file_systems: dict[str | PurePosixPath, _NetworkFileSystem] = {},
|
|
709
631
|
volumes: dict[str | PurePosixPath, _Volume | _CloudBucketMount] = {},
|
|
710
632
|
webhook_config: api_pb2.WebhookConfig | None = None,
|
|
711
633
|
cpu: float | tuple[float, float] | None = None,
|
|
@@ -827,7 +749,6 @@ class _Function(typing.Generic[P, ReturnType, OriginalReturnType], _Object, type
|
|
|
827
749
|
mounts=all_mounts,
|
|
828
750
|
secrets=secrets,
|
|
829
751
|
gpus=gpu,
|
|
830
|
-
network_file_systems=network_file_systems,
|
|
831
752
|
volumes=volumes,
|
|
832
753
|
image=image,
|
|
833
754
|
cloud=cloud,
|
|
@@ -905,9 +826,6 @@ class _Function(typing.Generic[P, ReturnType, OriginalReturnType], _Object, type
|
|
|
905
826
|
cloud_bucket_mounts = [(k, v) for k, v in validated_volumes if isinstance(v, _CloudBucketMount)]
|
|
906
827
|
validated_volumes_no_cloud_buckets = [(k, v) for k, v in validated_volumes if isinstance(v, _Volume)]
|
|
907
828
|
|
|
908
|
-
# Validate NFS
|
|
909
|
-
validated_network_file_systems = validate_network_file_systems(network_file_systems)
|
|
910
|
-
|
|
911
829
|
# Validate image
|
|
912
830
|
if image is not None and not isinstance(image, _Image): # type: ignore[unreachable]
|
|
913
831
|
raise InvalidError(f"Expected modal.Image object. Got {type(image)}.")
|
|
@@ -952,8 +870,6 @@ class _Function(typing.Generic[P, ReturnType, OriginalReturnType], _Object, type
|
|
|
952
870
|
deps.append(proxy)
|
|
953
871
|
if image:
|
|
954
872
|
deps.append(image)
|
|
955
|
-
for _, nfs in validated_network_file_systems:
|
|
956
|
-
deps.append(nfs)
|
|
957
873
|
for _, vol in validated_volumes_no_cloud_buckets:
|
|
958
874
|
deps.append(vol)
|
|
959
875
|
for _, cloud_bucket_mount in cloud_bucket_mounts:
|
|
@@ -1083,7 +999,6 @@ class _Function(typing.Generic[P, ReturnType, OriginalReturnType], _Object, type
|
|
|
1083
999
|
autoscaler_settings=autoscaler_settings,
|
|
1084
1000
|
method_definitions=method_definitions,
|
|
1085
1001
|
method_definitions_set=True,
|
|
1086
|
-
shared_volume_mounts=network_file_system_mount_protos(validated_network_file_systems),
|
|
1087
1002
|
volume_mounts=volume_mounts,
|
|
1088
1003
|
proxy_id=(proxy.object_id if proxy else None),
|
|
1089
1004
|
retry_policy=retry_policy,
|
|
@@ -1254,7 +1169,9 @@ class _Function(typing.Generic[P, ReturnType, OriginalReturnType], _Object, type
|
|
|
1254
1169
|
obj._build_args = dict(
|
|
1255
1170
|
secrets=repr(secrets),
|
|
1256
1171
|
gpu_config=repr([parse_gpu_config(_gpu) for _gpu in gpus]),
|
|
1257
|
-
network_file_systems
|
|
1172
|
+
# network_file_systems is part of the Image hash of `Image.run_function` layers. If we remove it,
|
|
1173
|
+
# every `run_function` Image would be rebuilt after upgrading.
|
|
1174
|
+
network_file_systems="{}",
|
|
1258
1175
|
)
|
|
1259
1176
|
# these key are excluded if empty to avoid rebuilds on client upgrade
|
|
1260
1177
|
if volumes:
|
|
@@ -2198,10 +2115,10 @@ class _Function(typing.Generic[P, ReturnType, OriginalReturnType], _Object, type
|
|
|
2198
2115
|
# TODO: check if we end up here in a container for a serialized function?
|
|
2199
2116
|
raise ExecutionError("Can't call .local on service function")
|
|
2200
2117
|
|
|
2201
|
-
if is_local() and self._spec_.volumes
|
|
2118
|
+
if is_local() and self._spec_.volumes:
|
|
2202
2119
|
warnings.warn(
|
|
2203
2120
|
f"The {info.function_name} function is executing locally "
|
|
2204
|
-
+ "and will not have access to the mounted Volume
|
|
2121
|
+
+ "and will not have access to the mounted Volume data"
|
|
2205
2122
|
)
|
|
2206
2123
|
|
|
2207
2124
|
obj: "modal.cls._Obj | None" = self._get_obj()
|
|
@@ -2343,15 +2260,15 @@ class _Function(typing.Generic[P, ReturnType, OriginalReturnType], _Object, type
|
|
|
2343
2260
|
Returns:
|
|
2344
2261
|
A `FunctionStats` object
|
|
2345
2262
|
"""
|
|
2346
|
-
until = until or datetime.now(
|
|
2263
|
+
until = until or datetime.now(UTC)
|
|
2347
2264
|
if until.tzinfo is None:
|
|
2348
2265
|
until = until.astimezone()
|
|
2349
|
-
until = until.astimezone(
|
|
2266
|
+
until = until.astimezone(UTC)
|
|
2350
2267
|
|
|
2351
2268
|
since = since or until - timedelta(hours=1)
|
|
2352
2269
|
if since.tzinfo is None:
|
|
2353
2270
|
since = since.astimezone()
|
|
2354
|
-
since = since.astimezone(
|
|
2271
|
+
since = since.astimezone(UTC)
|
|
2355
2272
|
if since >= until:
|
|
2356
2273
|
raise InvalidError("`since` must be before `until`.")
|
|
2357
2274
|
|
modal/_image.py
CHANGED
|
@@ -23,6 +23,7 @@ from typing import (
|
|
|
23
23
|
import typing_extensions
|
|
24
24
|
from google.protobuf.message import Message
|
|
25
25
|
from grpclib.exceptions import StreamTerminatedError
|
|
26
|
+
from synchronicity import classproperty
|
|
26
27
|
from typing_extensions import Self
|
|
27
28
|
|
|
28
29
|
from modal._serialization import serialize_data_format
|
|
@@ -60,7 +61,6 @@ from .exception import (
|
|
|
60
61
|
)
|
|
61
62
|
from .file_pattern_matcher import NON_PYTHON_FILES, FilePatternMatcher, _ignore_fn
|
|
62
63
|
from .mount import PYTHON_STANDALONE_VERSIONS, _Mount, python_standalone_mount_name
|
|
63
|
-
from .network_file_system import _NetworkFileSystem
|
|
64
64
|
from .output import OutputManager
|
|
65
65
|
from .secret import _Secret
|
|
66
66
|
from .volume import _Volume, _volume_to_mount_proto
|
|
@@ -574,6 +574,26 @@ class _FailedBuildAttempt:
|
|
|
574
574
|
client: _Client
|
|
575
575
|
|
|
576
576
|
|
|
577
|
+
class _ImageManager:
|
|
578
|
+
"""Namespace with methods for managing Image objects."""
|
|
579
|
+
|
|
580
|
+
async def delete(self, image_id: str, *, client: _Client | None = None) -> None:
|
|
581
|
+
"""Delete an Image by its ID.
|
|
582
|
+
|
|
583
|
+
Deletion is irreversible and prevents Functions and Sandboxes from using
|
|
584
|
+
this Image. Only the specified Image is deleted; intermediate layers
|
|
585
|
+
created by chained Image methods are not deleted.
|
|
586
|
+
|
|
587
|
+
Args:
|
|
588
|
+
image_id: Image object ID to delete.
|
|
589
|
+
client: Modal client to use; defaults to `Client.from_env()` when omitted.
|
|
590
|
+
"""
|
|
591
|
+
if client is None:
|
|
592
|
+
client = await _Client.from_env()
|
|
593
|
+
|
|
594
|
+
await client._stub.ImageDelete(api_pb2.ImageDeleteRequest(image_id=image_id))
|
|
595
|
+
|
|
596
|
+
|
|
577
597
|
class _Image(_Object, type_prefixes=("im",)):
|
|
578
598
|
"""Base class for container images to run functions in.
|
|
579
599
|
|
|
@@ -595,6 +615,11 @@ class _Image(_Object, type_prefixes=("im",)):
|
|
|
595
615
|
# A failed image ID is only queryable through the client that performed the build.
|
|
596
616
|
_failed_build_attempt: _FailedBuildAttempt | None = None
|
|
597
617
|
|
|
618
|
+
@classproperty
|
|
619
|
+
@classmethod
|
|
620
|
+
def objects(cls) -> _ImageManager:
|
|
621
|
+
return _ImageManager()
|
|
622
|
+
|
|
598
623
|
def _initialize_from_empty(self):
|
|
599
624
|
self.inside_exceptions = []
|
|
600
625
|
self._serve_mounts = frozenset()
|
|
@@ -2915,7 +2940,6 @@ class _Image(_Object, type_prefixes=("im",)):
|
|
|
2915
2940
|
env: dict[str, str | None] | None = None,
|
|
2916
2941
|
secrets: Collection[_Secret] | None = None,
|
|
2917
2942
|
volumes: dict[str | PurePosixPath, _Volume | _CloudBucketMount] = {},
|
|
2918
|
-
network_file_systems: dict[str | PurePosixPath, _NetworkFileSystem] = {},
|
|
2919
2943
|
gpu: str | list[str] | None = None,
|
|
2920
2944
|
cpu: float | None = None,
|
|
2921
2945
|
memory: int | None = None,
|
|
@@ -2943,7 +2967,6 @@ class _Image(_Object, type_prefixes=("im",)):
|
|
|
2943
2967
|
env: Environment variables set in the builder container.
|
|
2944
2968
|
secrets: Secrets available to the builder function.
|
|
2945
2969
|
volumes: Volume and bucket mounts attached for the build.
|
|
2946
|
-
network_file_systems: Network file systems attached for the build.
|
|
2947
2970
|
gpu: GPU type or list of types for the builder container.
|
|
2948
2971
|
cpu: CPU cores to request.
|
|
2949
2972
|
memory: Memory to request in MiB.
|
|
@@ -2994,7 +3017,6 @@ class _Image(_Object, type_prefixes=("im",)):
|
|
|
2994
3017
|
secrets=secrets,
|
|
2995
3018
|
gpu=gpu,
|
|
2996
3019
|
volumes=volumes,
|
|
2997
|
-
network_file_systems=network_file_systems,
|
|
2998
3020
|
cloud=cloud,
|
|
2999
3021
|
region=region,
|
|
3000
3022
|
memory=memory,
|
modal/_logs.py
CHANGED
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
import asyncio
|
|
5
5
|
import dataclasses
|
|
6
6
|
from collections.abc import AsyncGenerator, Awaitable, Callable
|
|
7
|
-
from datetime import datetime, timedelta
|
|
7
|
+
from datetime import UTC, datetime, timedelta
|
|
8
8
|
from typing import TYPE_CHECKING, Sequence, TypeVar
|
|
9
9
|
|
|
10
10
|
from google.protobuf.timestamp_pb2 import Timestamp
|
|
@@ -366,7 +366,7 @@ async def tail_logs(
|
|
|
366
366
|
if n > _FETCH_LIMIT:
|
|
367
367
|
raise LogsFetchError(f"--tail value must not exceed {_FETCH_LIMIT}.")
|
|
368
368
|
|
|
369
|
-
now = datetime.now(
|
|
369
|
+
now = datetime.now(UTC)
|
|
370
370
|
|
|
371
371
|
if since is not None and since.tzinfo is None:
|
|
372
372
|
raise ValueError("since must be timezone-aware")
|
modal/_logs_manager.py
CHANGED
|
@@ -7,7 +7,7 @@ import enum
|
|
|
7
7
|
import socket
|
|
8
8
|
import time
|
|
9
9
|
from collections.abc import AsyncGenerator, Awaitable, Callable
|
|
10
|
-
from datetime import
|
|
10
|
+
from datetime import UTC, datetime
|
|
11
11
|
|
|
12
12
|
from grpclib.exceptions import StreamTerminatedError
|
|
13
13
|
|
|
@@ -42,8 +42,8 @@ def _normalize_utc_datetime(value: datetime, name: str) -> datetime:
|
|
|
42
42
|
if not isinstance(value, datetime):
|
|
43
43
|
raise TypeError(f"{name} must be a datetime")
|
|
44
44
|
if value.tzinfo is None:
|
|
45
|
-
return value.replace(tzinfo=locale_tz()).astimezone(
|
|
46
|
-
return value.astimezone(
|
|
45
|
+
return value.replace(tzinfo=locale_tz()).astimezone(UTC)
|
|
46
|
+
return value.astimezone(UTC)
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
def _entry_source(file_descriptor: api_pb2.FileDescriptor.ValueType) -> LogSource:
|
|
@@ -58,8 +58,8 @@ def _entry_source(file_descriptor: api_pb2.FileDescriptor.ValueType) -> LogSourc
|
|
|
58
58
|
|
|
59
59
|
def _entry_timestamp(item: api_pb2.TaskLogs) -> datetime:
|
|
60
60
|
if item.timestamp_ns:
|
|
61
|
-
return datetime.fromtimestamp(item.timestamp_ns / 1_000_000_000,
|
|
62
|
-
return datetime.fromtimestamp(item.timestamp,
|
|
61
|
+
return datetime.fromtimestamp(item.timestamp_ns / 1_000_000_000, UTC)
|
|
62
|
+
return datetime.fromtimestamp(item.timestamp, UTC)
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
def _resolve_source(source: LogSource | None) -> api_pb2.FileDescriptor.ValueType:
|
|
@@ -147,7 +147,7 @@ class _LogsManager:
|
|
|
147
147
|
) -> AsyncGenerator[LogEntry, None]:
|
|
148
148
|
"""Fetch all associated logs corresponding to the date range and filters."""
|
|
149
149
|
since = _normalize_utc_datetime(since, "since")
|
|
150
|
-
until = _normalize_utc_datetime(until or datetime.now(
|
|
150
|
+
until = _normalize_utc_datetime(until or datetime.now(UTC), "until")
|
|
151
151
|
target = await self._params()
|
|
152
152
|
filters = dataclasses.replace(
|
|
153
153
|
target.filters,
|
|
@@ -670,10 +670,10 @@ class _FunctionCallLogsManager:
|
|
|
670
670
|
|
|
671
671
|
if since_was_defaulted:
|
|
672
672
|
function_call_info = await self._get_function_call_info()
|
|
673
|
-
since = datetime.fromtimestamp(function_call_info.created_at,
|
|
673
|
+
since = datetime.fromtimestamp(function_call_info.created_at, UTC)
|
|
674
674
|
|
|
675
675
|
if until_was_defaulted:
|
|
676
|
-
until = datetime.now(
|
|
676
|
+
until = datetime.now(UTC)
|
|
677
677
|
|
|
678
678
|
if since_was_defaulted and until_was_defaulted and since > until:
|
|
679
679
|
until = since
|
|
@@ -729,8 +729,8 @@ class _ImageLogsManager:
|
|
|
729
729
|
params.client,
|
|
730
730
|
step.builder_app_id,
|
|
731
731
|
# Protobuf timestamps represent UTC time.
|
|
732
|
-
since=step.started_at.ToDatetime(tzinfo=
|
|
733
|
-
until=step.finished_at.ToDatetime(tzinfo=
|
|
732
|
+
since=step.started_at.ToDatetime(tzinfo=UTC),
|
|
733
|
+
until=step.finished_at.ToDatetime(tzinfo=UTC),
|
|
734
734
|
filters=LogsFilters(
|
|
735
735
|
task_id=step.builder_task_id,
|
|
736
736
|
),
|
|
@@ -781,8 +781,8 @@ class _ImageLogsManager:
|
|
|
781
781
|
params.client,
|
|
782
782
|
step.builder_app_id,
|
|
783
783
|
remaining_entries,
|
|
784
|
-
since=step.started_at.ToDatetime(tzinfo=
|
|
785
|
-
until=step.finished_at.ToDatetime(tzinfo=
|
|
784
|
+
since=step.started_at.ToDatetime(tzinfo=UTC),
|
|
785
|
+
until=step.finished_at.ToDatetime(tzinfo=UTC),
|
|
786
786
|
filters=LogsFilters(task_id=step.builder_task_id),
|
|
787
787
|
):
|
|
788
788
|
for item in batch.items:
|
modal/_metrics.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Copyright Modal Labs 2026
|
|
2
2
|
from __future__ import annotations
|
|
3
3
|
|
|
4
|
-
from datetime import datetime, timedelta
|
|
4
|
+
from datetime import UTC, datetime, timedelta
|
|
5
5
|
|
|
6
6
|
from modal_proto import api_pb2
|
|
7
7
|
|
|
@@ -14,8 +14,8 @@ from .types import MetricDefinition, MetricSeries, MetricsSchema, ObjectMetrics,
|
|
|
14
14
|
def _metrics_request(
|
|
15
15
|
since: datetime | None, until: datetime | None, bucket_size: timedelta | None, groups: list[str] | None
|
|
16
16
|
) -> api_pb2.FunctionGetMetricsRequest:
|
|
17
|
-
until = (until or datetime.now(
|
|
18
|
-
since = (since or until - timedelta(hours=1)).astimezone(
|
|
17
|
+
until = (until or datetime.now(UTC)).astimezone(UTC)
|
|
18
|
+
since = (since or until - timedelta(hours=1)).astimezone(UTC)
|
|
19
19
|
if since >= until:
|
|
20
20
|
raise InvalidError("`since` must be before `until`.")
|
|
21
21
|
if since.timestamp() < 0:
|
|
@@ -50,7 +50,7 @@ def _object_metrics(
|
|
|
50
50
|
description=item.description,
|
|
51
51
|
points=[
|
|
52
52
|
TimeSeriesPoint(
|
|
53
|
-
time=point.timestamp.ToDatetime(tzinfo=
|
|
53
|
+
time=point.timestamp.ToDatetime(tzinfo=UTC),
|
|
54
54
|
value=point.value if point.HasField("value") else None,
|
|
55
55
|
)
|
|
56
56
|
for point in item.points
|
|
@@ -60,8 +60,8 @@ def _object_metrics(
|
|
|
60
60
|
}
|
|
61
61
|
return ObjectMetrics(
|
|
62
62
|
object_id=object_id,
|
|
63
|
-
since=response.since.ToDatetime(tzinfo=
|
|
64
|
-
until=response.until.ToDatetime(tzinfo=
|
|
63
|
+
since=response.since.ToDatetime(tzinfo=UTC),
|
|
64
|
+
until=response.until.ToDatetime(tzinfo=UTC),
|
|
65
65
|
bucket_size=timedelta(seconds=response.bucket_secs),
|
|
66
66
|
point_count=sum(len(item.points) for item in series.values()),
|
|
67
67
|
series=series,
|
modal/_object.py
CHANGED
|
@@ -108,12 +108,22 @@ class _Object:
|
|
|
108
108
|
|
|
109
109
|
@property
|
|
110
110
|
def _is_hydrated(self) -> bool:
|
|
111
|
+
"""Whether the object has a client, identity, and any static metadata needed for interaction."""
|
|
111
112
|
return self.__is_hydrated
|
|
112
113
|
|
|
113
114
|
@_is_hydrated.setter
|
|
114
115
|
def _is_hydrated(self, value: bool):
|
|
115
116
|
self.__is_hydrated = value
|
|
116
117
|
|
|
118
|
+
def _is_serializable(self) -> bool:
|
|
119
|
+
"""Whether the object can be serialized
|
|
120
|
+
|
|
121
|
+
Serializability can be more relaxed than hydration: clients are not serialized,
|
|
122
|
+
and many types need only an object_id, allowing handles created with from_id()
|
|
123
|
+
to be serialized before hydration.
|
|
124
|
+
"""
|
|
125
|
+
return self._is_hydrated
|
|
126
|
+
|
|
117
127
|
@classmethod
|
|
118
128
|
def __init_subclass__(cls, type_prefixes: Sequence[str] = ()):
|
|
119
129
|
super().__init_subclass__()
|
|
@@ -180,6 +190,9 @@ class _Object:
|
|
|
180
190
|
self._client = other._client
|
|
181
191
|
|
|
182
192
|
def _hydrate(self, object_id: str, client: _Client, metadata: Message | None):
|
|
193
|
+
"""Hydration makes an object usable: it has a valid Client and object_id, and for some
|
|
194
|
+
types static metadata required or recommended for interaction.
|
|
195
|
+
"""
|
|
183
196
|
assert isinstance(object_id, str) and self._type_prefixes
|
|
184
197
|
if not self._has_type_prefix(object_id):
|
|
185
198
|
raise ExecutionError(
|
modal/_resolver.py
CHANGED
|
@@ -4,11 +4,13 @@ import os
|
|
|
4
4
|
import tempfile
|
|
5
5
|
from asyncio import Future
|
|
6
6
|
from collections.abc import Hashable
|
|
7
|
+
from functools import cached_property
|
|
7
8
|
|
|
8
9
|
import modal._object
|
|
9
10
|
from modal._traceback import suppress_tb_frame
|
|
10
11
|
|
|
11
12
|
from ._load_context import LoadContext
|
|
13
|
+
from ._utils.blob_utils import _ByteBudget
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
class Resolver:
|
|
@@ -29,6 +31,10 @@ class Resolver:
|
|
|
29
31
|
def build_start(self) -> float:
|
|
30
32
|
return self._build_start
|
|
31
33
|
|
|
34
|
+
@cached_property
|
|
35
|
+
def mount_upload_byte_budget(self) -> _ByteBudget:
|
|
36
|
+
return _ByteBudget.from_system_memory()
|
|
37
|
+
|
|
32
38
|
async def preload(
|
|
33
39
|
self, obj: "modal._object._Object", parent_load_context: "LoadContext", existing_object_id: str | None
|
|
34
40
|
):
|
modal/_runtime/asgi.py
CHANGED
|
@@ -158,7 +158,7 @@ def asgi_app_wrapper(asgi_app, container_io_manager) -> tuple[Callable[..., Asyn
|
|
|
158
158
|
# see comment above about manual cancellation
|
|
159
159
|
first_message_task.cancel()
|
|
160
160
|
raise
|
|
161
|
-
except (
|
|
161
|
+
except (TimeoutError, StopAsyncIteration):
|
|
162
162
|
# About `StopAsyncIteration` above: The generator shouldn't typically exit,
|
|
163
163
|
# but if it does, we handle it like a timeout in that case.
|
|
164
164
|
await handle_first_input_timeout()
|
modal/_serialization.py
CHANGED