baseten-loops 0.35.0a1__tar.gz → 0.35.0.dev2__tar.gz
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.
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/PKG-INFO +1 -4
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_request_log.py +3 -14
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_urls.py +0 -10
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/http_errors.py +0 -14
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/models.py +10 -165
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/promise_client.py +3 -23
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/retry.py +7 -101
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/sampling_client.py +30 -2
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/service_client.py +170 -383
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/training_client.py +47 -293
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/pyproject.toml +1 -3
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/conftest.py +1 -125
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_async_paths.py +7 -2
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_chunking.py +0 -60
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_create_lora_training_client.py +151 -14
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_promise_client.py +0 -75
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_provenance.py +49 -0
- baseten_loops-0.35.0a1/baseten/loops/_fft_sampling.py +0 -979
- baseten_loops-0.35.0a1/baseten/loops/_full_finetune.py +0 -787
- baseten_loops-0.35.0a1/baseten/loops/_hot_load_keeper.py +0 -197
- baseten_loops-0.35.0a1/baseten/loops/_llm_models.py +0 -105
- baseten_loops-0.35.0a1/baseten/loops/_sampler_configs.py +0 -382
- baseten_loops-0.35.0a1/baseten/loops/_sampler_templates.py +0 -166
- baseten_loops-0.35.0a1/baseten/loops/_snapshot_cli.py +0 -500
- baseten_loops-0.35.0a1/baseten/loops/_volume_snapshots.py +0 -241
- baseten_loops-0.35.0a1/baseten/loops/_volumes.py +0 -532
- baseten_loops-0.35.0a1/baseten/loops/experimental/__init__.py +0 -4
- baseten_loops-0.35.0a1/baseten/loops/experimental/fft.py +0 -1029
- baseten_loops-0.35.0a1/baseten/loops/hot_load.py +0 -678
- baseten_loops-0.35.0a1/tests/fixtures/rl-rollouts/models/qwen3.8-27b/h200-1/config.yaml +0 -82
- baseten_loops-0.35.0a1/tests/test_delete_snapshot_volume.py +0 -175
- baseten_loops-0.35.0a1/tests/test_direct_trainer.py +0 -426
- baseten_loops-0.35.0a1/tests/test_fft_async_rl_example.py +0 -1082
- baseten_loops-0.35.0a1/tests/test_fft_sampling_client.py +0 -1274
- baseten_loops-0.35.0a1/tests/test_full_finetune.py +0 -1788
- baseten_loops-0.35.0a1/tests/test_hot_load.py +0 -863
- baseten_loops-0.35.0a1/tests/test_hot_load_keeper.py +0 -354
- baseten_loops-0.35.0a1/tests/test_list_snapshots.py +0 -584
- baseten_loops-0.35.0a1/tests/test_pull_tokens.py +0 -314
- baseten_loops-0.35.0a1/tests/test_sampler_configs.py +0 -184
- baseten_loops-0.35.0a1/tests/test_sampler_templates.py +0 -238
- baseten_loops-0.35.0a1/tests/test_snapshot_cli.py +0 -401
- baseten_loops-0.35.0a1/tests/test_volume_versions.py +0 -134
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/.gitignore +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/CHANGELOG.md +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/LICENSE +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/__init__.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_async_client.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_capacity.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_chat_templates.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_checkpoint_download.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_checkpoints.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_h2_transport.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_headers.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_heartbeat.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_runs.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_sampler_replicas.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_samplers.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_sampling_keepalive.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_session_filter.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_sync_bridge.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_tracing.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_version.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/_workers.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/cache.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/helpers/__init__.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/helpers/datum.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/operation.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/provenance.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/renderers.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/rl_metrics.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/baseten/loops/trainer_deployment.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/acceptance_math_rl.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/acceptance_multiturn_rl.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/fixtures/glm5_3_flash_hf_render.json +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/fixtures/provenance_contract.json +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/fixtures/vlm_model_input_chunks.json +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/h2_server.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_adam_params.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_cache.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_capacity.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_capacity_refused_create.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_create_training_client_from_state.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_datum.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_download_checkpoint.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_ensure_ready.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_forward_backward.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_forward_backward_custom.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_get_checkpoint_archive_url.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_get_server_capabilities.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_headers.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_heartbeat_keepalive.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_lazy_async_client.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_lazy_paired_sampler.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_list_checkpoints.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_model_input.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_operation_context.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_pipelining.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_policy_version.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_provenance_contract.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_queued_sampling.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_renderers.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_request_log.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_request_ordering.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_retry.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_rl_metrics.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_run_id_in_op_bodies.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_sample_timeout.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_sampling_client_close.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_sampling_client_pickle.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_sampling_parse.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_sampling_tcp_keepalive.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_sampling_transport_repro.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_save_weights_for_sampler_bump.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_serverless_errors.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_serverless_unique_save_names.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_session_recovery.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_snapshot_sampling_client.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_standalone_sampler_lifecycle.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_team_scoped_routes.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_training_client.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_training_run_lifecycle.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_vlm_chunks.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_wait_for_trainer_ready.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_wandb.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_with_sampler.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/test_workers.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/tests/verify_worker.py +0 -0
- {baseten_loops-0.35.0a1 → baseten_loops-0.35.0.dev2}/uv.lock +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: baseten-loops
|
|
3
|
-
Version: 0.35.
|
|
3
|
+
Version: 0.35.0.dev2
|
|
4
4
|
Summary: SDK for Baseten training workers
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -8,7 +8,6 @@ Requires-Python: >=3.12
|
|
|
8
8
|
Requires-Dist: baseten-bdn<1,>=0.1
|
|
9
9
|
Requires-Dist: datasets>=4.8.4
|
|
10
10
|
Requires-Dist: httpx[http2]>=0.24.1
|
|
11
|
-
Requires-Dist: jinja2>=3.1.0
|
|
12
11
|
Requires-Dist: opentelemetry-api>=1.27.0
|
|
13
12
|
Requires-Dist: opentelemetry-instrumentation-httpx>=0.48b0
|
|
14
13
|
Requires-Dist: opentelemetry-sdk>=1.27.0
|
|
@@ -17,8 +16,6 @@ Requires-Dist: tenacity>=8.0.0
|
|
|
17
16
|
Requires-Dist: tiktoken>=0.7.0
|
|
18
17
|
Requires-Dist: transformers>=4.40.0
|
|
19
18
|
Requires-Dist: wandb>=0.26.1
|
|
20
|
-
Provides-Extra: fft
|
|
21
|
-
Requires-Dist: pyyaml>=6.0; extra == 'fft'
|
|
22
19
|
Provides-Extra: tinker
|
|
23
20
|
Requires-Dist: baseten-loops-tinker>=0.3.0; extra == 'tinker'
|
|
24
21
|
Provides-Extra: torch
|
|
@@ -8,8 +8,7 @@ request and one per response, so a run can be replayed later.
|
|
|
8
8
|
Every httpx client is built through ``make_sync_client`` / ``make_async_client``
|
|
9
9
|
so the record hooks see all traffic. Lines are correlated by a monotonic
|
|
10
10
|
``seq`` and stamped with a UTC ``ts``. Bodies are logged in full (token tensors,
|
|
11
|
-
base64 images included), so logs can be large
|
|
12
|
-
the ``SECRET_BODY`` extension: its body and its response's are logged redacted.
|
|
11
|
+
base64 images included), so logs can be large.
|
|
13
12
|
"""
|
|
14
13
|
|
|
15
14
|
from __future__ import annotations
|
|
@@ -32,9 +31,6 @@ _REDACTED = "[REDACTED]"
|
|
|
32
31
|
# trainer or sampler): a lookup, a deactivate or a validate.
|
|
33
32
|
API_TIMEOUT_SEC = 60.0
|
|
34
33
|
|
|
35
|
-
# Request extension marking a body that carries secrets, such as store credentials.
|
|
36
|
-
SECRET_BODY = "baseten_loops_secret_body"
|
|
37
|
-
|
|
38
34
|
|
|
39
35
|
def _now_iso() -> str:
|
|
40
36
|
return (
|
|
@@ -64,13 +60,6 @@ def _parse_body(content: bytes) -> object:
|
|
|
64
60
|
return {"_unparseable": True, "len": len(content)}
|
|
65
61
|
|
|
66
62
|
|
|
67
|
-
def _logged_body(request: httpx.Request, content: bytes) -> object:
|
|
68
|
-
"""``content`` of ``request`` or its response, as the log records it."""
|
|
69
|
-
if request.extensions.get(SECRET_BODY):
|
|
70
|
-
return _REDACTED
|
|
71
|
-
return _parse_body(content)
|
|
72
|
-
|
|
73
|
-
|
|
74
63
|
class RequestLog:
|
|
75
64
|
"""Records every request/response to ``log_path``.
|
|
76
65
|
|
|
@@ -128,7 +117,7 @@ class RequestLog:
|
|
|
128
117
|
"url": str(request.url),
|
|
129
118
|
"path": request.url.raw_path.decode("ascii"),
|
|
130
119
|
"headers": _redact_headers(request.headers),
|
|
131
|
-
"body":
|
|
120
|
+
"body": _parse_body(request.content),
|
|
132
121
|
}
|
|
133
122
|
)
|
|
134
123
|
|
|
@@ -145,7 +134,7 @@ class RequestLog:
|
|
|
145
134
|
"elapsed_ms": elapsed_ms,
|
|
146
135
|
"status": response.status_code,
|
|
147
136
|
"headers": _redact_headers(response.headers),
|
|
148
|
-
"body":
|
|
137
|
+
"body": _parse_body(response.content),
|
|
149
138
|
}
|
|
150
139
|
)
|
|
151
140
|
|
|
@@ -2,18 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
import os
|
|
6
5
|
from urllib.parse import urlencode
|
|
7
6
|
|
|
8
|
-
DEFAULT_API_BASE_URL = "https://api.baseten.co"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def resolve_api_base_url(base_url: str | None) -> str:
|
|
12
|
-
"""The Baseten API base URL: ``base_url``, else ``LOOPS_BASE_URL``, else the
|
|
13
|
-
public API."""
|
|
14
|
-
base = base_url or os.environ.get("LOOPS_BASE_URL", DEFAULT_API_BASE_URL)
|
|
15
|
-
return base.rstrip("/")
|
|
16
|
-
|
|
17
7
|
|
|
18
8
|
def loops_api_root(base_url: str, team_id: str | None) -> str:
|
|
19
9
|
"""Root URL for the Loops create endpoints; no team means the org default team."""
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import json
|
|
6
|
-
import re
|
|
7
6
|
|
|
8
7
|
import httpx
|
|
9
8
|
|
|
@@ -19,19 +18,6 @@ from baseten.loops._headers import (
|
|
|
19
18
|
# model's 400 body is {"error": "<message>"} and never carries it.
|
|
20
19
|
_VLLM_INVALID_REQUEST_TYPE = "BadRequestError"
|
|
21
20
|
|
|
22
|
-
_REDACTED = "[REDACTED]"
|
|
23
|
-
# How pydantic prints an invalid input; a server could quote one in an error.
|
|
24
|
-
_PYDANTIC_INPUT = re.compile(r"input_value=.*?(?=, input_type=|\]|$)", re.DOTALL)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def redact(text: str, secrets: list[str]) -> str:
|
|
28
|
-
"""``text`` without ``secrets``, or any input pydantic quoted in it."""
|
|
29
|
-
text = _PYDANTIC_INPUT.sub(f"input_value={_REDACTED}", text)
|
|
30
|
-
for secret in sorted(secrets, key=len, reverse=True):
|
|
31
|
-
if secret:
|
|
32
|
-
text = text.replace(secret, _REDACTED)
|
|
33
|
-
return text
|
|
34
|
-
|
|
35
21
|
|
|
36
22
|
def _extract_error_details(resp: httpx.Response) -> str | None:
|
|
37
23
|
"""Best-effort extraction of structured error details from the response body."""
|
|
@@ -3,22 +3,18 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import base64
|
|
6
|
-
import json
|
|
7
6
|
from datetime import datetime
|
|
8
7
|
from enum import StrEnum
|
|
9
8
|
from pathlib import Path
|
|
10
9
|
from typing import Annotated, Any, Dict, List, Literal, Self, Tuple, TypeAlias, Union
|
|
11
10
|
|
|
12
11
|
from pydantic import (
|
|
13
|
-
AwareDatetime,
|
|
14
12
|
BaseModel,
|
|
15
13
|
ConfigDict,
|
|
16
14
|
Discriminator,
|
|
17
15
|
Field,
|
|
18
16
|
PositiveInt,
|
|
19
|
-
SecretStr,
|
|
20
17
|
Tag,
|
|
21
|
-
ValidationError,
|
|
22
18
|
field_serializer,
|
|
23
19
|
field_validator,
|
|
24
20
|
model_validator,
|
|
@@ -37,7 +33,14 @@ from baseten.loops.provenance import SampledProvenanceSpan as SampledProvenanceS
|
|
|
37
33
|
SupportedImageFormat: TypeAlias = Literal["png", "jpeg"]
|
|
38
34
|
|
|
39
35
|
LossFnType: TypeAlias = Literal[
|
|
40
|
-
"cross_entropy",
|
|
36
|
+
"cross_entropy",
|
|
37
|
+
"importance_sampling",
|
|
38
|
+
"ppo",
|
|
39
|
+
"cispo",
|
|
40
|
+
"dro",
|
|
41
|
+
"dpo",
|
|
42
|
+
"dppo",
|
|
43
|
+
"score_centered_reinforce",
|
|
41
44
|
]
|
|
42
45
|
|
|
43
46
|
StopReason: TypeAlias = Literal["stop", "length"]
|
|
@@ -278,10 +281,6 @@ class SampledSequence(BaseModel):
|
|
|
278
281
|
logprobs: List[float] | None = None
|
|
279
282
|
stop_reason: StopReason = "length"
|
|
280
283
|
text: str | None = None
|
|
281
|
-
# Set by RL Rollouts Samplers: the Snapshot Name and Policy Version of
|
|
282
|
-
# the weights that generated this sequence.
|
|
283
|
-
snapshot_name: str | None = None
|
|
284
|
-
policy_version: int | None = None
|
|
285
284
|
|
|
286
285
|
|
|
287
286
|
class SampleResponse(BaseModel):
|
|
@@ -348,154 +347,6 @@ class SaveWeightsResponse(BaseModel):
|
|
|
348
347
|
path: str = ""
|
|
349
348
|
|
|
350
349
|
|
|
351
|
-
class StoreCredentials(BaseModel):
|
|
352
|
-
"""S3 credentials that can write under a full-finetune Trainer's store.
|
|
353
|
-
|
|
354
|
-
The client sends them only to its own Trainer, which keeps them in memory.
|
|
355
|
-
``repr``, ``str``, ``model_dump`` and validation errors never show them.
|
|
356
|
-
"""
|
|
357
|
-
|
|
358
|
-
model_config = ConfigDict(frozen=True, extra="forbid", hide_input_in_errors=True)
|
|
359
|
-
|
|
360
|
-
aws_access_key_id: SecretStr
|
|
361
|
-
aws_secret_access_key: SecretStr
|
|
362
|
-
aws_region: str = Field(min_length=1)
|
|
363
|
-
aws_session_token: SecretStr | None = None
|
|
364
|
-
|
|
365
|
-
@classmethod
|
|
366
|
-
def from_json_file(cls, path: str | Path) -> Self:
|
|
367
|
-
"""Read credentials from a JSON object with ``aws_access_key_id``,
|
|
368
|
-
``aws_secret_access_key``, ``aws_region`` and, optionally,
|
|
369
|
-
``aws_session_token``. Errors name the problem, never the file's contents."""
|
|
370
|
-
path = Path(path).expanduser()
|
|
371
|
-
try:
|
|
372
|
-
data = json.loads(path.read_text())
|
|
373
|
-
except json.JSONDecodeError as exc:
|
|
374
|
-
problem = (
|
|
375
|
-
f"{path} is not valid JSON (line {exc.lineno}, column {exc.colno})"
|
|
376
|
-
)
|
|
377
|
-
else:
|
|
378
|
-
try:
|
|
379
|
-
return cls.model_validate(data)
|
|
380
|
-
except ValidationError as exc:
|
|
381
|
-
problem = f"{path} does not hold store credentials: " + "; ".join(
|
|
382
|
-
f"{'.'.join(map(str, error['loc'])) or 'file'}: {error['msg']}"
|
|
383
|
-
for error in exc.errors(include_input=False, include_url=False)
|
|
384
|
-
)
|
|
385
|
-
# Raised outside the handlers: a chained error would carry the contents.
|
|
386
|
-
raise ValueError(problem)
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
class _TrainerStore(BaseModel):
|
|
390
|
-
"""A prefix in object storage that a full-finetune Trainer writes to.
|
|
391
|
-
|
|
392
|
-
``credentials`` can write under ``uri``. A Trainer the Loops control plane
|
|
393
|
-
provisions needs them; one you deployed with its stores configured does not.
|
|
394
|
-
"""
|
|
395
|
-
|
|
396
|
-
model_config = ConfigDict(frozen=True, hide_input_in_errors=True)
|
|
397
|
-
|
|
398
|
-
uri: str = Field(pattern=r"^[a-z][a-z0-9+.-]*://[^/]+")
|
|
399
|
-
credentials: StoreCredentials | None = None
|
|
400
|
-
|
|
401
|
-
@field_validator("uri")
|
|
402
|
-
@classmethod
|
|
403
|
-
def _without_trailing_slash(cls, uri: str) -> str:
|
|
404
|
-
# Names are joined as {uri}/{name}/; a trailing slash would add an empty
|
|
405
|
-
# key segment that a Sampler reading {uri} never looks under.
|
|
406
|
-
return uri.rstrip("/")
|
|
407
|
-
|
|
408
|
-
def contains(self, path: str) -> bool:
|
|
409
|
-
"""Whether ``path`` names an entry under this store, such as
|
|
410
|
-
``{uri}/step-4``."""
|
|
411
|
-
if not path.startswith(f"{self.uri}/"):
|
|
412
|
-
return False
|
|
413
|
-
segments = path[len(self.uri) + 1 :].rstrip("/").split("/")
|
|
414
|
-
return all(segment not in ("", ".", "..") for segment in segments)
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
class SnapshotStore(_TrainerStore):
|
|
418
|
-
"""Where a full-finetune Trainer publishes Snapshots for Samplers to hot-load.
|
|
419
|
-
|
|
420
|
-
Each Snapshot lands under ``{uri}/{snapshot_name}/``; deploy the Samplers
|
|
421
|
-
against the same ``uri``.
|
|
422
|
-
"""
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
class TrainingCheckpointStore(_TrainerStore):
|
|
426
|
-
"""Where a full-finetune Trainer writes and reads its Training Checkpoints
|
|
427
|
-
(``save_state`` / ``load_state``). Samplers never read it; keep it apart
|
|
428
|
-
from the Snapshot Store."""
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
SnapshotKind: TypeAlias = Literal["full", "delta"]
|
|
432
|
-
|
|
433
|
-
StoreType: TypeAlias = Literal["s3", "cannery"]
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
class PublishedSnapshot(BaseModel):
|
|
437
|
-
"""A Snapshot a full-finetune Trainer published.
|
|
438
|
-
|
|
439
|
-
``store`` says where: ``"s3"``, under its S3 Snapshot Store, or
|
|
440
|
-
``"cannery"``, into the Baseten BDN volume Loops gave it, where ``ref``
|
|
441
|
-
(``bdn:loops/<volume>:<tag>``) names it and ``digest`` (``b3:<64 hex>``) pins
|
|
442
|
-
its contents. Trainers that predate Cannery report no ``store``: they publish
|
|
443
|
-
to S3. ``changed_fraction`` is the share of the weights that differ from the
|
|
444
|
-
parent, as the Trainer reported it on publishing; a Snapshot read back from
|
|
445
|
-
its volume (``list_snapshots``) has ``None``. ``policy_version`` is the
|
|
446
|
-
Policy Version of its weights. Send ``hot_load_request`` as-is to each
|
|
447
|
-
Sampler's hot-load API (``baseten.loops.experimental.fft.hot_load``) to make
|
|
448
|
-
it serve this Snapshot.
|
|
449
|
-
"""
|
|
450
|
-
|
|
451
|
-
name: str
|
|
452
|
-
kind: SnapshotKind
|
|
453
|
-
# None for a Full Snapshot.
|
|
454
|
-
parent_name: str | None
|
|
455
|
-
bytes_written: int
|
|
456
|
-
changed_fraction: float | None
|
|
457
|
-
hot_load_request: Dict[str, Any]
|
|
458
|
-
store: StoreType = "s3"
|
|
459
|
-
# Set for a Cannery Snapshot.
|
|
460
|
-
ref: str | None = None
|
|
461
|
-
digest: str | None = None
|
|
462
|
-
policy_version: int | None = None
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
class PullToken(BaseModel):
|
|
466
|
-
"""A short-lived token that reads one Baseten BDN volume, which a Sampler
|
|
467
|
-
pulls a Cannery Snapshot with.
|
|
468
|
-
|
|
469
|
-
``bdn_endpoint`` is the volume API it authenticates against, ``None`` where
|
|
470
|
-
the environment exposes none. It lasts an hour, until ``expires_at``, and
|
|
471
|
-
cannot be renewed. ``repr``, ``str``, ``model_dump`` and validation errors
|
|
472
|
-
never show it.
|
|
473
|
-
"""
|
|
474
|
-
|
|
475
|
-
model_config = ConfigDict(frozen=True, hide_input_in_errors=True)
|
|
476
|
-
|
|
477
|
-
token: SecretStr
|
|
478
|
-
bdn_endpoint: str | None = None
|
|
479
|
-
expires_at: AwareDatetime
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
class DeployedSnapshot(BaseModel):
|
|
483
|
-
"""A Baseten model whose vLLM server serves a Full Snapshot.
|
|
484
|
-
|
|
485
|
-
``status`` is the deployment's when the push returned, ``ACTIVE`` once it
|
|
486
|
-
was waited for. ``predict_url`` is the deployment's predict route, which
|
|
487
|
-
the server answers as ``/v1/chat/completions``; ``chat_completions_url``
|
|
488
|
-
is that route under the deployment's sync URL, beside the server's other
|
|
489
|
-
OpenAI routes.
|
|
490
|
-
"""
|
|
491
|
-
|
|
492
|
-
model_id: str
|
|
493
|
-
deployment_id: str
|
|
494
|
-
status: str
|
|
495
|
-
predict_url: str
|
|
496
|
-
chat_completions_url: str
|
|
497
|
-
|
|
498
|
-
|
|
499
350
|
class SaveWeightsForSamplerResponse(BaseModel):
|
|
500
351
|
"""Response for ``/save_weights_for_sampler`` (the trainer-side
|
|
501
352
|
publish-LoRA endpoint).
|
|
@@ -503,22 +354,16 @@ class SaveWeightsForSamplerResponse(BaseModel):
|
|
|
503
354
|
``version`` is the controller's ``step_count`` at the moment of the
|
|
504
355
|
call — clients don't pass it. Two syncs at the same version mean
|
|
505
356
|
"no new weights since last check"; a sampler watching the URI keys
|
|
506
|
-
its hot-swap on this number.
|
|
507
|
-
Snapshot's Policy Version.
|
|
357
|
+
its hot-swap on this number.
|
|
508
358
|
|
|
509
359
|
``path`` is where the adapters were published. On serverless weight
|
|
510
360
|
sync it is the ``bt://loops:<run>/sampler_weights/<name>`` path to
|
|
511
361
|
pin a sampler to (no trailing slash). On S3 weight sync
|
|
512
|
-
it is the checkpoint subdirectory (``{weight_sync_uri}/{name}/``).
|
|
513
|
-
a full-finetune Trainer it is the Snapshot's directory in the S3
|
|
514
|
-
Snapshot Store, or for a Cannery Snapshot its ``ref``.
|
|
515
|
-
|
|
516
|
-
``snapshot`` is set by full-finetune Trainers only.
|
|
362
|
+
it is the checkpoint subdirectory (``{weight_sync_uri}/{name}/``).
|
|
517
363
|
"""
|
|
518
364
|
|
|
519
365
|
version: int = 0
|
|
520
366
|
path: str = ""
|
|
521
|
-
snapshot: PublishedSnapshot | None = None
|
|
522
367
|
|
|
523
368
|
|
|
524
369
|
class LoadWeightsResponse(BaseModel):
|
|
@@ -46,12 +46,7 @@ from baseten.loops._headers import IDEMPOTENCY_KEY_HEADER
|
|
|
46
46
|
from baseten.loops._workers import run_poll
|
|
47
47
|
from baseten.loops.http_errors import raise_for_status_with_details
|
|
48
48
|
from baseten.loops.operation import Operation
|
|
49
|
-
from baseten.loops.retry import
|
|
50
|
-
Early404Window,
|
|
51
|
-
post_with_retry,
|
|
52
|
-
post_with_retry_async,
|
|
53
|
-
retry_after_sec,
|
|
54
|
-
)
|
|
49
|
+
from baseten.loops.retry import post_with_retry, post_with_retry_async, retry_after_sec
|
|
55
50
|
|
|
56
51
|
logger = logging.getLogger(__name__)
|
|
57
52
|
|
|
@@ -215,7 +210,6 @@ def _poll_operation(
|
|
|
215
210
|
result_cls: type[T],
|
|
216
211
|
*,
|
|
217
212
|
ready_timeout: float | None = 3600.0,
|
|
218
|
-
early_404s: Early404Window | None = None,
|
|
219
213
|
) -> T:
|
|
220
214
|
"""Long-poll ``GET /operations/{operation_id}`` until the op finishes.
|
|
221
215
|
|
|
@@ -234,7 +228,6 @@ def _poll_operation(
|
|
|
234
228
|
|
|
235
229
|
``ready_timeout`` caps the total wall time spent polling. Pass ``None``
|
|
236
230
|
to poll indefinitely until the op completes or raises a terminal error.
|
|
237
|
-
A 404 inside ``early_404s`` is re-polled after a brief sleep instead.
|
|
238
231
|
"""
|
|
239
232
|
deadline = math.inf if ready_timeout is None else time.monotonic() + ready_timeout
|
|
240
233
|
operation_id = operation.operation_id
|
|
@@ -254,9 +247,6 @@ def _poll_operation(
|
|
|
254
247
|
continue
|
|
255
248
|
|
|
256
249
|
if resp.status_code == 404:
|
|
257
|
-
if early_404s is not None and early_404s.resends(resp):
|
|
258
|
-
time.sleep(_POLL_BACKOFF_SEC)
|
|
259
|
-
continue
|
|
260
250
|
# Server doesn't know this id, OR it knew and the result was
|
|
261
251
|
# evicted — same recovery either way (resubmit).
|
|
262
252
|
raise UnknownRequestError(
|
|
@@ -335,7 +325,6 @@ async def _poll_operation_async(
|
|
|
335
325
|
retry_after_statuses: frozenset[int] = frozenset(),
|
|
336
326
|
transient_statuses: frozenset[int] = _POLL_TRANSIENT_STATUSES,
|
|
337
327
|
poll_timeout: httpx.Timeout = httpx.Timeout(_POLL_READ_TIMEOUT_SEC),
|
|
338
|
-
early_404s: Early404Window | None = None,
|
|
339
328
|
) -> T:
|
|
340
329
|
"""Async version of :func:`_poll_operation` — uses ``asyncio.sleep`` for
|
|
341
330
|
back-off so the event loop is never blocked between polls.
|
|
@@ -343,8 +332,7 @@ async def _poll_operation_async(
|
|
|
343
332
|
``retry_after_statuses`` re-polls those statuses after the wait their
|
|
344
333
|
Retry-After asks for, and raises them without one; listing 503 replaces the
|
|
345
334
|
shutdown meaning. ``transient_statuses`` re-poll after a brief sleep.
|
|
346
|
-
``poll_timeout`` is each poll's httpx timeout.
|
|
347
|
-
re-polls after a brief sleep too.
|
|
335
|
+
``poll_timeout`` is each poll's httpx timeout.
|
|
348
336
|
"""
|
|
349
337
|
deadline = math.inf if ready_timeout is None else time.monotonic() + ready_timeout
|
|
350
338
|
operation_id = operation.operation_id
|
|
@@ -371,9 +359,6 @@ async def _poll_operation_async(
|
|
|
371
359
|
raise_for_status_with_details(resp)
|
|
372
360
|
|
|
373
361
|
if resp.status_code == 404:
|
|
374
|
-
if early_404s is not None and early_404s.resends(resp):
|
|
375
|
-
await asyncio.sleep(_POLL_BACKOFF_SEC)
|
|
376
|
-
continue
|
|
377
362
|
raise UnknownRequestError(
|
|
378
363
|
f"server has no record of operation_id {operation_id} "
|
|
379
364
|
"(either never submitted or TTL-evicted; resubmit)"
|
|
@@ -443,8 +428,7 @@ class APIFuture(Generic[T]):
|
|
|
443
428
|
|
|
444
429
|
Result consumption matches the prior threadpool-backed future. Construction
|
|
445
430
|
requires an ``Operation`` descriptor rather than a bare ID; SDK clients
|
|
446
|
-
build it when the server accepts a submission.
|
|
447
|
-
``early_404s`` is re-polled instead of raised.
|
|
431
|
+
build it when the server accepts a submission.
|
|
448
432
|
"""
|
|
449
433
|
|
|
450
434
|
def __init__(
|
|
@@ -455,7 +439,6 @@ class APIFuture(Generic[T]):
|
|
|
455
439
|
result_cls: type[T],
|
|
456
440
|
ready_timeout: float | None = 3600.0,
|
|
457
441
|
async_client: _LazyAsyncClient | None = None,
|
|
458
|
-
early_404s: Early404Window | None = None,
|
|
459
442
|
) -> None:
|
|
460
443
|
self._client = client
|
|
461
444
|
self._async_client = async_client
|
|
@@ -463,7 +446,6 @@ class APIFuture(Generic[T]):
|
|
|
463
446
|
self._operation = operation
|
|
464
447
|
self._result_cls = result_cls
|
|
465
448
|
self._ready_timeout = ready_timeout
|
|
466
|
-
self._early_404s = early_404s
|
|
467
449
|
self._lock = threading.Lock()
|
|
468
450
|
self._async_lock: asyncio.Lock | None = None
|
|
469
451
|
self._cached: Optional[T] = None
|
|
@@ -503,7 +485,6 @@ class APIFuture(Generic[T]):
|
|
|
503
485
|
ready_timeout=timeout
|
|
504
486
|
if timeout is not None
|
|
505
487
|
else self._ready_timeout,
|
|
506
|
-
early_404s=self._early_404s,
|
|
507
488
|
)
|
|
508
489
|
return self._cached
|
|
509
490
|
except BaseException as e:
|
|
@@ -535,7 +516,6 @@ class APIFuture(Generic[T]):
|
|
|
535
516
|
ready_timeout=timeout
|
|
536
517
|
if timeout is not None
|
|
537
518
|
else self._ready_timeout,
|
|
538
|
-
early_404s=self._early_404s,
|
|
539
519
|
)
|
|
540
520
|
return self._cached
|
|
541
521
|
except BaseException as e:
|
|
@@ -10,10 +10,6 @@ jittered exponential backoff, never sooner than the Retry-After, for at most
|
|
|
10
10
|
``MAX_CAPACITY_TRIES`` attempts unless the caller lifts that limit, and within
|
|
11
11
|
``ready_timeout``, then raised as :class:`LoopsCapacityError`.
|
|
12
12
|
Any other 429 (such as the gateway's usage limit) is raised at once.
|
|
13
|
-
|
|
14
|
-
A new Trainer's ingress can answer its routes 404 for a moment after the Trainer
|
|
15
|
-
reports ready. Clients that know when it did resend those 404s inside an
|
|
16
|
-
:class:`Early404Window`.
|
|
17
13
|
"""
|
|
18
14
|
|
|
19
15
|
from __future__ import annotations
|
|
@@ -21,8 +17,6 @@ from __future__ import annotations
|
|
|
21
17
|
import logging
|
|
22
18
|
import math
|
|
23
19
|
import random
|
|
24
|
-
import time
|
|
25
|
-
from dataclasses import dataclass
|
|
26
20
|
from typing import Callable, Dict
|
|
27
21
|
|
|
28
22
|
import httpx
|
|
@@ -65,41 +59,6 @@ _CAPACITY_REASON = "loops_capacity"
|
|
|
65
59
|
# Spreads the clients the queue refused together, so they don't all retry at once.
|
|
66
60
|
_CAPACITY_JITTER_FRACTION = 0.2
|
|
67
61
|
|
|
68
|
-
# How long after a Trainer reports ready a 404 from its routes is resent.
|
|
69
|
-
EARLY_404_WINDOW_SEC = 60.0
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
@dataclass(frozen=True)
|
|
73
|
-
class Early404Window:
|
|
74
|
-
"""Until when a new Trainer's 404s are resent instead of raised.
|
|
75
|
-
|
|
76
|
-
``until`` is a ``time.monotonic()`` reading. After it, a 404 from the
|
|
77
|
-
Trainer's routes means what it always does.
|
|
78
|
-
"""
|
|
79
|
-
|
|
80
|
-
until: float
|
|
81
|
-
|
|
82
|
-
@classmethod
|
|
83
|
-
def after_ready(cls) -> Early404Window:
|
|
84
|
-
"""The window that opens now, as the Trainer reports ready."""
|
|
85
|
-
return cls(time.monotonic() + EARLY_404_WINDOW_SEC)
|
|
86
|
-
|
|
87
|
-
def resends(self, resp: httpx.Response) -> bool:
|
|
88
|
-
"""Whether to send ``resp``'s request again: a 404 inside the window,
|
|
89
|
-
logged."""
|
|
90
|
-
left = self.until - time.monotonic()
|
|
91
|
-
if resp.status_code != 404 or left <= 0:
|
|
92
|
-
return False
|
|
93
|
-
logger.info(
|
|
94
|
-
"The Trainer answered %s %s with 404 right after it reported ready; "
|
|
95
|
-
"resending (404s are resent for %.0fs more).",
|
|
96
|
-
resp.request.method,
|
|
97
|
-
resp.request.url.path,
|
|
98
|
-
left,
|
|
99
|
-
)
|
|
100
|
-
return True
|
|
101
|
-
|
|
102
|
-
|
|
103
62
|
# Transient httpx failures where the request was either never sent or its
|
|
104
63
|
# response was lost. Treat them the same as a "server not ready" status —
|
|
105
64
|
# the underlying operation is idempotent on the loops protocol, and these
|
|
@@ -199,62 +158,13 @@ class _stop_after_capacity_tries(stop_base):
|
|
|
199
158
|
)
|
|
200
159
|
|
|
201
160
|
|
|
202
|
-
class _stop_after_status_tries(stop_base):
|
|
203
|
-
"""Stop once ``tries`` attempts have been made and the last failed with one
|
|
204
|
-
of ``statuses``."""
|
|
205
|
-
|
|
206
|
-
def __init__(self, statuses: frozenset[int], tries: int):
|
|
207
|
-
self._statuses = statuses
|
|
208
|
-
self._tries = tries
|
|
209
|
-
|
|
210
|
-
def __call__(self, retry_state: RetryCallState) -> bool:
|
|
211
|
-
outcome = retry_state.outcome
|
|
212
|
-
exc = outcome.exception() if outcome is not None else None
|
|
213
|
-
return (
|
|
214
|
-
isinstance(exc, httpx.HTTPStatusError)
|
|
215
|
-
and exc.response.status_code in self._statuses
|
|
216
|
-
and retry_state.attempt_number >= self._tries
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
|
|
220
161
|
def _stop(
|
|
221
|
-
ready_timeout: float | None,
|
|
222
|
-
capacity_tries: int | None = MAX_CAPACITY_TRIES,
|
|
223
|
-
bounded_statuses: frozenset[int] = frozenset(),
|
|
224
|
-
bounded_tries: int = 1,
|
|
162
|
+
ready_timeout: float | None, capacity_tries: int | None = MAX_CAPACITY_TRIES
|
|
225
163
|
) -> stop_base:
|
|
226
|
-
|
|
227
|
-
if capacity_tries is
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
stop = stop | _stop_after_status_tries(bounded_statuses, bounded_tries)
|
|
231
|
-
return stop
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
def warn_before_resend(log: logging.Logger) -> Callable[[RetryCallState], None]:
|
|
235
|
-
"""A ``before_sleep`` that logs each resend at WARNING, with the failed
|
|
236
|
-
attempt's status and the start of its body."""
|
|
237
|
-
|
|
238
|
-
def _warn(state: RetryCallState) -> None:
|
|
239
|
-
exc = state.outcome.exception() if state.outcome is not None else None
|
|
240
|
-
if isinstance(exc, httpx.HTTPStatusError):
|
|
241
|
-
reason = f"HTTP {exc.response.status_code}: {exc.response.text[:200]}"
|
|
242
|
-
else:
|
|
243
|
-
reason = repr(exc)
|
|
244
|
-
request = (
|
|
245
|
-
exc.request
|
|
246
|
-
if isinstance(exc, (httpx.HTTPStatusError, httpx.RequestError))
|
|
247
|
-
else None
|
|
248
|
-
)
|
|
249
|
-
log.warning(
|
|
250
|
-
"Attempt %d of %s failed (%s); sending it again in %.1f s.",
|
|
251
|
-
state.attempt_number,
|
|
252
|
-
f"{request.method} {request.url}" if request is not None else "a request",
|
|
253
|
-
reason,
|
|
254
|
-
state.next_action.sleep if state.next_action is not None else 0.0,
|
|
255
|
-
)
|
|
256
|
-
|
|
257
|
-
return _warn
|
|
164
|
+
timeout = stop_never if ready_timeout is None else stop_after_delay(ready_timeout)
|
|
165
|
+
if capacity_tries is None:
|
|
166
|
+
return timeout
|
|
167
|
+
return timeout | _stop_after_capacity_tries(capacity_tries)
|
|
258
168
|
|
|
259
169
|
|
|
260
170
|
def _wait_honoring_retry_after(
|
|
@@ -393,8 +303,6 @@ async def post_with_retry_async(
|
|
|
393
303
|
retry_statuses: frozenset[int] = NOT_READY_STATUSES,
|
|
394
304
|
retry_after_statuses: frozenset[int] = frozenset(),
|
|
395
305
|
capacity_tries: int | None = MAX_CAPACITY_TRIES,
|
|
396
|
-
bounded_statuses: frozenset[int] = frozenset(),
|
|
397
|
-
bounded_tries: int = 1,
|
|
398
306
|
) -> httpx.Response:
|
|
399
307
|
"""Async version of :func:`post_with_retry` using ``httpx.AsyncClient``.
|
|
400
308
|
|
|
@@ -413,16 +321,14 @@ async def post_with_retry_async(
|
|
|
413
321
|
as long as it asks. A capacity refusal is backed off on as in
|
|
414
322
|
:func:`post_with_retry`, and raised as :class:`LoopsCapacityError`.
|
|
415
323
|
``capacity_tries`` bounds how many refusals are retried; ``None`` retries them
|
|
416
|
-
until ``ready_timeout``.
|
|
417
|
-
sent at most ``bounded_tries`` times, then raised: a server error that the
|
|
418
|
-
request itself may cause is not waited on for the whole ``ready_timeout``.
|
|
324
|
+
until ``ready_timeout``.
|
|
419
325
|
"""
|
|
420
326
|
wait = wait_exponential_jitter(initial=1, max=30, jitter=5)
|
|
421
327
|
|
|
422
328
|
@retry(
|
|
423
329
|
retry=retry_if_exception(_retryable_for(retry_statuses, retry_after_statuses)),
|
|
424
330
|
wait=_wait_honoring_retry_after(retry_after_statuses, wait, ready_timeout),
|
|
425
|
-
stop=_stop(ready_timeout, capacity_tries
|
|
331
|
+
stop=_stop(ready_timeout, capacity_tries),
|
|
426
332
|
before_sleep=before_sleep or before_sleep_log(logger, logging.INFO),
|
|
427
333
|
reraise=True,
|
|
428
334
|
)
|