Compute Engine Single-VM submitter¶
gce_submit
¶
Submit a run (or family slice) to a single Google Compute Engine VM (runtime="gce").
Why a direct Compute Engine single-VM runtime beside Vertex CustomJob, Spark, and Ray:
1. Direct GCE Compute Quota & Zonal Placement: Runs directly on standard Compute Engine VM
quotas (CPUS, N2_CPUS, NVIDIA_T4_GPUS, NVIDIA_L4_GPUS) across candidate zones via
compute_fallback.resolve_candidates, without needing Vertex AI CustomJob training quota or a
multi-node Dataproc/Ray cluster.
2. Identical Container + Dynamic GCS Code Delivery: Boots Google's Container-Optimized OS
(projects/cos-cloud/global/images/family/cos-stable), pulls SF_CONTAINER_IMAGE from Artifact
Registry, downloads gs://<code_bucket>/runs/scale_forecasting-<code_hash>.zip via
VERTEX_BOOTSTRAP_CODE, and executes scale_forecasting.vertex_entry (vertex_engine.run).
3. Triple-Redundant Zero-Orphan VM Lifecycle:
- Layer 1 — GCE Hypervisor Hard TTL: Every VM is created with
scheduling.maxRunDuration + scheduling.instanceTerminationAction = "DELETE" and
automaticRestart = False, so the Compute Engine hypervisor unconditionally deletes the VM
when its TTL expires even if both the client process and the guest OS crash.
- Layer 2 — Guest OS trap cleanup EXIT Self-Deletion: The Container-Optimized OS startup
script registers trap cleanup EXIT on line 1. As soon as the container exits (whether exit 0
or non-zero), cleanup() writes a JSON status marker (SUCCEEDED or FAILED + container tail
logs) to gs://<code_bucket>/runs/gce-status/<instance_name>.json and calls the Compute Engine
REST API (DELETE .../instances/<instance_name>) using the VM's metadata OAuth token.
- Layer 3 — Client-Side try ... finally Teardown & GceProbe.cancel(): submit_gce
deletes the instance in a finally block (idempotent on 404 Not Found if the guest already
self-deleted) and cancels + deletes on stall-watchdog or wait timeout.
GceInstancePlan
dataclass
¶
GceInstancePlan(
instance_name,
machine_type,
accelerator_type,
accelerator_count,
hardware,
gpu_type,
image_uri="",
package_uri="",
config_uri="",
service_account="",
subnetwork_uri="",
status_bucket="",
status_object="",
max_run_duration_seconds=7200,
boot_disk_gb=_DEFAULT_BOOT_DISK_GB,
resource_plan=None,
)
Resolved execution plan for a single-VM Compute Engine run (pure).
status_uri
property
¶
Full gs:// URI of the status marker object, or empty string when unset.
to_dict
¶
JSON-safe summary for run_jobs.job_telemetry.$.gce_instance.
Source code in src/scale_forecasting/gce_submit.py
build_gce_instance_spec_dict
¶
build_gce_instance_spec_dict(
plan,
driver_args=(),
*,
project_id="project",
zone="us-central1-a",
labels=None,
)
Build the Compute Engine instances.insert REST request body (pure).
Enforces triple-redundant zero-orphan lifecycle guarantees:
1. scheduling.maxRunDuration + scheduling.instanceTerminationAction = "DELETE" +
scheduling.automaticRestart = False (hypervisor-level hard TTL deletion).
2. metadata.items[startup-script] with trap cleanup EXIT self-deletion via GCE REST API.
3. disks[0].autoDelete = True so the boot persistent disk never outlives the VM.
Source code in src/scale_forecasting/gce_submit.py
build_gce_startup_script
¶
Render the Container-Optimized OS startup script with trap cleanup EXIT self-delete (pure).
Uses only POSIX shell + curl + sed + docker so it has zero dependency on a host Python
installation on Container-Optimized OS (cos-stable).
Source code in src/scale_forecasting/gce_submit.py
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 | |
delete_instance
¶
Best-effort delete of a GCE instance; returns True if a delete was accepted, False on 404.
Source code in src/scale_forecasting/gce_submit.py
get_instance
¶
Return the Compute Engine instance resource dict, or None on 404.
Source code in src/scale_forecasting/gce_submit.py
plan_gce_job
¶
plan_gce_job(
cfg,
models=None,
*,
run_id=None,
job_id=None,
instance_name=None,
hardware=None,
gpu_type=None,
machine_type=None,
accelerator_count=None,
image_uri="",
package_uri="",
config_uri="",
service_account="",
subnetwork_uri="",
status_bucket="",
max_run_duration_seconds=7200,
ttl_seconds=None,
profile=None,
settings=None,
infra=None,
)
Resolve a single-VM GceInstancePlan from cfg and per-family overrides (pure).
Source code in src/scale_forecasting/gce_submit.py
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 | |
read_status_marker
¶
Read the GCS status marker written by submit_gce / the guest startup script, or None.
Source code in src/scale_forecasting/gce_submit.py
resolve_gce_candidates
¶
Explicit-zone candidates for GCE VM creation (pure).
Compute Engine instances.insert is zonal, so auto-zone (zone=None) entries from
resolve_candidates are expanded to explicit zones (US_ZONES fallback when needed).
Source code in src/scale_forecasting/gce_submit.py
status_object_path
¶
GCS object path holding the terminal status marker for a GCE VM (pure).
submit_gce
¶
submit_gce(
cfg,
settings=None,
infra=None,
*,
wait=True,
models=None,
job_id=None,
instance_name=None,
manage_header=True,
hardware=None,
gpu_type=None,
machine_type=None,
accelerator_count=None,
)
Stage config + code and run on a single Compute Engine VM with zero-orphan teardown.
Returns (run_id, instance_resource_path, probe_handle).
Source code in src/scale_forecasting/gce_submit.py
739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | |