xmanager-slurm 0.3.2__py3-none-any.whl → 0.4.1__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.

Potentially problematic release.


This version of xmanager-slurm might be problematic. Click here for more details.

Files changed (42) hide show
  1. xm_slurm/__init__.py +6 -2
  2. xm_slurm/api.py +301 -34
  3. xm_slurm/batching.py +4 -4
  4. xm_slurm/config.py +105 -55
  5. xm_slurm/constants.py +19 -0
  6. xm_slurm/contrib/__init__.py +0 -0
  7. xm_slurm/contrib/clusters/__init__.py +47 -13
  8. xm_slurm/contrib/clusters/drac.py +34 -16
  9. xm_slurm/dependencies.py +171 -0
  10. xm_slurm/executables.py +34 -22
  11. xm_slurm/execution.py +305 -107
  12. xm_slurm/executors.py +8 -12
  13. xm_slurm/experiment.py +601 -168
  14. xm_slurm/experimental/parameter_controller.py +202 -0
  15. xm_slurm/job_blocks.py +7 -0
  16. xm_slurm/packageables.py +42 -20
  17. xm_slurm/packaging/{docker/local.py → docker.py} +135 -40
  18. xm_slurm/packaging/router.py +3 -1
  19. xm_slurm/packaging/utils.py +9 -81
  20. xm_slurm/resources.py +28 -4
  21. xm_slurm/scripts/_cloudpickle.py +28 -0
  22. xm_slurm/scripts/cli.py +52 -0
  23. xm_slurm/status.py +9 -0
  24. xm_slurm/templates/docker/mamba.Dockerfile +4 -2
  25. xm_slurm/templates/docker/python.Dockerfile +18 -10
  26. xm_slurm/templates/docker/uv.Dockerfile +35 -0
  27. xm_slurm/templates/slurm/fragments/monitor.bash.j2 +5 -0
  28. xm_slurm/templates/slurm/job-array.bash.j2 +1 -2
  29. xm_slurm/templates/slurm/job.bash.j2 +4 -3
  30. xm_slurm/types.py +23 -0
  31. xm_slurm/utils.py +18 -10
  32. xmanager_slurm-0.4.1.dist-info/METADATA +26 -0
  33. xmanager_slurm-0.4.1.dist-info/RECORD +44 -0
  34. {xmanager_slurm-0.3.2.dist-info → xmanager_slurm-0.4.1.dist-info}/WHEEL +1 -1
  35. xmanager_slurm-0.4.1.dist-info/entry_points.txt +2 -0
  36. xmanager_slurm-0.4.1.dist-info/licenses/LICENSE.md +227 -0
  37. xm_slurm/packaging/docker/__init__.py +0 -75
  38. xm_slurm/packaging/docker/abc.py +0 -112
  39. xm_slurm/packaging/docker/cloud.py +0 -503
  40. xm_slurm/templates/docker/pdm.Dockerfile +0 -31
  41. xmanager_slurm-0.3.2.dist-info/METADATA +0 -25
  42. xmanager_slurm-0.3.2.dist-info/RECORD +0 -38
@@ -0,0 +1,35 @@
1
+ # syntax=docker/dockerfile:1.4
2
+ ARG BASE_IMAGE=docker.io/python:3.10-slim-bookworm
3
+ FROM $BASE_IMAGE
4
+ COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
5
+
6
+ ARG EXTRA_SYSTEM_PACKAGES=""
7
+ ARG EXTRA_PYTHON_PACKAGES=""
8
+
9
+ WORKDIR /workspace
10
+
11
+ ENV UV_PYTHON_DOWNLOADS=0
12
+ ENV UV_COMPILE_BYTECODE=1
13
+ ENV UV_LINK_MODE=copy
14
+
15
+ RUN apt-get update \
16
+ && apt-get install -y --no-install-recommends \
17
+ git $EXTRA_SYSTEM_PACKAGES \
18
+ && rm -rf /var/lib/apt/lists/*
19
+
20
+ RUN uv pip install --system pysocks $EXTRA_PYTHON_PACKAGES
21
+
22
+ RUN --mount=type=cache,target=/root/.cache/uv \
23
+ --mount=type=bind,source=uv.lock,target=uv.lock \
24
+ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
25
+ --mount=type=ssh \
26
+ uv sync --frozen --no-install-project --no-dev --no-editable
27
+
28
+ COPY --link . /workspace
29
+ RUN --mount=type=cache,target=/root/.cache/uv \
30
+ --mount=type=ssh \
31
+ uv sync --frozen --no-dev
32
+
33
+ ENV PATH="/workspace/.venv/bin:$PATH"
34
+
35
+ ENTRYPOINT [ "uv", "run", "python" ]
@@ -24,6 +24,11 @@ __xm_slurm_wait_for_children() {
24
24
  echo "INFO: Received requeue exit code {{ requeue_exit_code }} from job ${job}. Requeing Slurm job ${JOB_ID} after ${SLURM_RESTART_COUNT-0} restarts." >&2
25
25
  scontrol requeue "${JOB_ID}"
26
26
  exit {{ requeue_exit_code }}
27
+ elif [ "${JOB_EXIT_CODE}" -ne 0 ]; then
28
+ echo "ERROR: Job ${job} exited with code ${JOB_EXIT_CODE}." >&2
29
+ exit "${JOB_EXIT_CODE}"
30
+ else
31
+ echo "INFO: Job ${job} exited successfully." >&2
27
32
  fi
28
33
  done
29
34
  }
@@ -2,8 +2,7 @@
2
2
  {% block directives %}
3
3
  {{ super() -}}
4
4
  #SBATCH --array=0-{{ args | length - 1 }}
5
- #SBATCH --output=xm-%j-%a.stdout
6
- #SBATCH --error=xm-%j-%a.stderr
5
+ #SBATCH --output=slurm-%A_%a.out
7
6
  {% endblock directives %}
8
7
 
9
8
  {% block bootstrap %}
@@ -2,8 +2,7 @@
2
2
  {% block directives %}
3
3
  #SBATCH --open-mode=append
4
4
  #SBATCH --export=NONE
5
- #SBATCH --output=xm-%j.stdout
6
- #SBATCH --error=xm-%j.stderr
5
+ #SBATCH --output=slurm-%j.out
7
6
  #SBATCH --comment="{'xid': {{ experiment_id }}}"
8
7
  {% if cluster.account and not job.executor.account %}
9
8
  #SBATCH --account={{ cluster.account }}
@@ -16,8 +15,10 @@
16
15
  {% endif %}
17
16
  {% if identity %}
18
17
  #SBATCH --job-name=xm[{{ experiment_id }}.{{ identity }}]
19
- #SBATCH --dependency=singleton
20
18
  {% else %}
19
+ {% if dependency %}
20
+ #SBATCH {{ dependency.to_directive() }}
21
+ {% endif %}
21
22
  #SBATCH --job-name=xm[{{ experiment_id }}]
22
23
  {% endif %}
23
24
  {% for directive in job.executor.to_directives() %}
xm_slurm/types.py ADDED
@@ -0,0 +1,23 @@
1
+ import typing as tp
2
+
3
+ InstanceT_contra = tp.TypeVar("InstanceT_contra", contravariant=True)
4
+ GetterT_co = tp.TypeVar("GetterT_co", covariant=True)
5
+ SetterT_co = tp.TypeVar("SetterT_co", contravariant=True)
6
+
7
+
8
+ class Descriptor(tp.Protocol[GetterT_co, SetterT_co]):
9
+ def __set_name__(self, owner: tp.Type[tp.Any], name: str) -> None: ...
10
+
11
+ @tp.overload
12
+ def __get__(
13
+ self, instance: InstanceT_contra, owner: tp.Type[InstanceT_contra] | None = None
14
+ ) -> GetterT_co: ...
15
+
16
+ @tp.overload
17
+ def __get__(self, instance: None, owner: tp.Type[InstanceT_contra]) -> GetterT_co: ...
18
+
19
+ def __get__(
20
+ self, instance: InstanceT_contra | None, owner: tp.Type[InstanceT_contra] | None = None
21
+ ) -> GetterT_co: ...
22
+
23
+ def __set__(self, instance: tp.Any, value: SetterT_co) -> None: ...
xm_slurm/utils.py CHANGED
@@ -35,17 +35,17 @@ class UserSet(Hashable, MutableSet[T]):
35
35
  def __repr__(self):
36
36
  return repr(self.data)
37
37
 
38
- def add(self, item: T):
39
- self.data.add(item)
40
- self._on_add(item)
38
+ def add(self, value: T):
39
+ self.data.add(value)
40
+ self._on_add(value)
41
41
 
42
- def remove(self, item: T):
43
- self.data.remove(item)
44
- self._on_remove(item)
42
+ def remove(self, value: T):
43
+ self.data.remove(value)
44
+ self._on_remove(value)
45
45
 
46
- def discard(self, item: T):
47
- self.data.discard(item)
48
- self._on_discard(item)
46
+ def discard(self, value: T):
47
+ self.data.discard(value)
48
+ self._on_discard(value)
49
49
 
50
50
 
51
51
  @functools.cache
@@ -62,7 +62,15 @@ def find_project_root() -> pathlib.Path:
62
62
 
63
63
  pdir = launch_script_path.parent if launch_script_path else pathlib.Path.cwd().resolve()
64
64
  while pdir != pdir.parent:
65
- if (pdir / "pyproject.toml").exists():
65
+ if (
66
+ (pdir / "pyproject.toml").exists()
67
+ or (pdir / "setup.py").exists()
68
+ or (pdir / "setup.cfg").exists()
69
+ or (pdir / "requirements.txt").exists()
70
+ or (pdir / "requirements.in").exists()
71
+ or (pdir / "uv.lock").exists()
72
+ or (pdir / ".venv").exists()
73
+ ):
66
74
  return pdir
67
75
  pdir = pdir.parent
68
76
 
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.3
2
+ Name: xmanager-slurm
3
+ Version: 0.4.1
4
+ Summary: Slurm backend for XManager.
5
+ Project-URL: GitHub, https://github.com/jessefarebro/xm-slurm
6
+ Author-email: Jesse Farebrother <jfarebro@cs.mcgill.ca>
7
+ License: MIT
8
+ License-File: LICENSE.md
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Python: >=3.10
17
+ Requires-Dist: asyncssh>=2.13.2
18
+ Requires-Dist: backoff>=2.2.1
19
+ Requires-Dist: cloudpickle>=3.0.0
20
+ Requires-Dist: humanize>=4.8.0
21
+ Requires-Dist: immutabledict>=3.0.0
22
+ Requires-Dist: jinja2>=3.1.2
23
+ Requires-Dist: more-itertools>=10.2.0
24
+ Requires-Dist: rich>=13.5.2
25
+ Requires-Dist: toml>=0.10.2
26
+ Requires-Dist: xmanager>=0.5.0
@@ -0,0 +1,44 @@
1
+ xm_slurm/__init__.py,sha256=Ld2w7ofLlTieWOHP_Jb3f48-qtVQBjFXynxUm9WF8mc,1116
2
+ xm_slurm/api.py,sha256=LeGgHz82t8Oay0Z1Ourv9-r-DBur3lhCUTnmmGhGFY4,18502
3
+ xm_slurm/batching.py,sha256=GbKBsNz9w8gIc2fHLZpslC0e4K9YUfLXFHmjduRRCfQ,4385
4
+ xm_slurm/config.py,sha256=GLLEkRLJxQW0urmHCLmwq_4ECmimEBQFl8Nz62SIo78,6787
5
+ xm_slurm/console.py,sha256=UpMqeJ0C8i0pkue1AHnnyyX0bFJ9zZeJ7HBR6yhuA8A,54
6
+ xm_slurm/constants.py,sha256=zefVtlFdflgSolie5g_rVxWV-Zpydxapchm3y0a2FDc,999
7
+ xm_slurm/dependencies.py,sha256=-5gN_tpfs3dOA7H5_MIHO2ratb7F5Pm_yjkR5rZcgI8,6421
8
+ xm_slurm/executables.py,sha256=S3z8jSDL6AdyGYpzy_cCs03Mj0vgA4ZTqIe8APYor3E,6469
9
+ xm_slurm/execution.py,sha256=i2oYH5RS-mHsHPwFDFZvo5qCudbgqBML-Hzq6DPNItw,25721
10
+ xm_slurm/executors.py,sha256=fMtxGUCi4vEKmb_p4JEpqPUTh7L_f1LcR_TamMLAWNg,4667
11
+ xm_slurm/experiment.py,sha256=trHapcYxPNKofzSqu7KZawML59tZ8FVjoEZYe2Wal7w,44521
12
+ xm_slurm/job_blocks.py,sha256=_F8CKCs5BQFj40a2-mjG71HfacvWoBXBDPDKEaKTbXc,616
13
+ xm_slurm/packageables.py,sha256=YZFTL6UWx9A_zyztTy1THUlj3pW1rA0cBPHJxD1LOJk,12884
14
+ xm_slurm/resources.py,sha256=EaYDATVudrEDPKKdSZoWgfqPiidc6DMjIctmzLQmiH0,5683
15
+ xm_slurm/status.py,sha256=WTWiDHi-ZHtwHRnDP0cGa-27zTSm6LkA-GCKsN-zBgg,6916
16
+ xm_slurm/types.py,sha256=TsVykDm-LazVkrjeJrTwCMs4Q8APKhy7BTk0yKIhFNg,805
17
+ xm_slurm/utils.py,sha256=ESjOkGT7bRSzIeZrUtZplSHP4oaH6VZ92y2woYdcyKM,2239
18
+ xm_slurm/contrib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
+ xm_slurm/contrib/clusters/__init__.py,sha256=vugR50D9fPJQN5bTd7cSArDGrA6pC-YJHMXrEyvr_Uw,2980
20
+ xm_slurm/contrib/clusters/drac.py,sha256=tJeQFWFIpeZ1gD3j6AAJssNoLSiDkB-3lz1_ObnkRhc,5905
21
+ xm_slurm/experimental/parameter_controller.py,sha256=b5LfglHV307F6QcPrHeZX5GJBtyOK9aQydke_SZ3Wto,8457
22
+ xm_slurm/packaging/__init__.py,sha256=dh307yLpUT9KN7rJ1e9fYC6hegGKfZcGboUq9nGpDVQ,233
23
+ xm_slurm/packaging/docker.py,sha256=TA8-QG09EdhF4K1ixrEboVFarF9LcURNHhzUXL-7Iqg,11518
24
+ xm_slurm/packaging/registry.py,sha256=GrdmQg9MgSo38OiqOzMKWSkQyBuyryOfc3zcdgZ4CUE,1148
25
+ xm_slurm/packaging/router.py,sha256=yPbdA9clrhly97cLgDsSRZG2LZRKE-oz8Hhdb7WtYqk,2070
26
+ xm_slurm/packaging/utils.py,sha256=KI5s32rNTCfgwzY_7Ghck27jHKvKg5sl5_NEEqJbJqI,3999
27
+ xm_slurm/scripts/_cloudpickle.py,sha256=dlJYf2SceOuUn8wi-ozuoYAQg71wqD2MUVOUCyOwWIY,647
28
+ xm_slurm/scripts/cli.py,sha256=ZXqYOs8X23TYDdKxvV-wIa-0mTfpxSl4_Pli6TiKI7s,1435
29
+ xm_slurm/templates/docker/docker-bake.hcl.j2,sha256=ClsFpj91Mr1VfA8L6eqBG3HQz0Z8VenF6mEfmAhQgUo,1498
30
+ xm_slurm/templates/docker/mamba.Dockerfile,sha256=Sgxr5IA5T-pT1Shumb5k3JngoG4pgCdBXjzqslFJdZI,753
31
+ xm_slurm/templates/docker/python.Dockerfile,sha256=U4b4QVkopckQ0o9jJIE7d_M6TvExEYlYDirNwCoZ7W4,865
32
+ xm_slurm/templates/docker/uv.Dockerfile,sha256=kYD32oUS1jUaARsNV1o6EFnIfLCNh5GMmck27b-5NRU,969
33
+ xm_slurm/templates/slurm/job-array.bash.j2,sha256=iYtGMRDXgwwc2_8E3v4a30f3fKuq4zWgZHkxCXJ9iXc,567
34
+ xm_slurm/templates/slurm/job-group.bash.j2,sha256=UkjfBE7jg9mepcUWaHZEAjkiXsIM1j_sLxLzxkteD-Y,1120
35
+ xm_slurm/templates/slurm/job.bash.j2,sha256=v0xGYzagDdWW6Tg44qobGJLNSUP1Cf4CcekrPibYdrE,1864
36
+ xm_slurm/templates/slurm/fragments/monitor.bash.j2,sha256=HYqYhXsTv8TCed5UaGCZVGIYsqxSKHcnPyNNTHWNvxc,1279
37
+ xm_slurm/templates/slurm/fragments/proxy.bash.j2,sha256=VJLglZo-Nvx9R-qe3rHTxr07CylTQ6Z9NwBzvIpAZrA,814
38
+ xm_slurm/templates/slurm/runtimes/apptainer.bash.j2,sha256=dMntzelhs8DqKyIpO9S6wzMfH2PDevmgvyjCW8Xc2dY,3222
39
+ xm_slurm/templates/slurm/runtimes/podman.bash.j2,sha256=xKXYFvQvazMx0PgvmlRXR6eecoiBUl8y52dIzQtWkBE,1469
40
+ xmanager_slurm-0.4.1.dist-info/METADATA,sha256=3mT4XIm8evv-5qw7oney4nYn3IasIA_l1rWz86XNOY8,954
41
+ xmanager_slurm-0.4.1.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
42
+ xmanager_slurm-0.4.1.dist-info/entry_points.txt,sha256=_HLGmLgxuQLOPmF2gOFYDVq2HqtMVD_SzigHvUh8TCY,49
43
+ xmanager_slurm-0.4.1.dist-info/licenses/LICENSE.md,sha256=IxstXr3MPHwTJ5jMrByHrQsR1ZAGQ2U_uz_4qzI_15Y,11756
44
+ xmanager_slurm-0.4.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: pdm-backend (2.3.0)
2
+ Generator: hatchling 1.25.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ xm = xm_slurm.scripts.cli:main
@@ -0,0 +1,227 @@
1
+ This work is dual-licensed under Apache 2.0 and MIT License attached below.
2
+ You can choose between one of them if you use this work.
3
+
4
+ ---
5
+
6
+ The MIT License (MIT)
7
+ =====================
8
+
9
+ Copyright © `2024` `Jesse Farebrother`
10
+
11
+ Permission is hereby granted, free of charge, to any person
12
+ obtaining a copy of this software and associated documentation
13
+ files (the “Software”), to deal in the Software without
14
+ restriction, including without limitation the rights to use,
15
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the
17
+ Software is furnished to do so, subject to the following
18
+ conditions:
19
+
20
+ The above copyright notice and this permission notice shall be
21
+ included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
24
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30
+ OTHER DEALINGS IN THE SOFTWARE.
31
+
32
+ ---
33
+
34
+ Apache License
35
+ ==============
36
+
37
+ _Version 2.0, January 2004_
38
+ _&lt;<http://www.apache.org/licenses/>&gt;_
39
+
40
+ ### Terms and Conditions for use, reproduction, and distribution
41
+
42
+ #### 1. Definitions
43
+
44
+ “License” shall mean the terms and conditions for use, reproduction, and
45
+ distribution as defined by Sections 1 through 9 of this document.
46
+
47
+ “Licensor” shall mean the copyright owner or entity authorized by the copyright
48
+ owner that is granting the License.
49
+
50
+ “Legal Entity” shall mean the union of the acting entity and all other entities
51
+ that control, are controlled by, or are under common control with that entity.
52
+ For the purposes of this definition, “control” means **(i)** the power, direct or
53
+ indirect, to cause the direction or management of such entity, whether by
54
+ contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
55
+ outstanding shares, or **(iii)** beneficial ownership of such entity.
56
+
57
+ “You” (or “Your”) shall mean an individual or Legal Entity exercising
58
+ permissions granted by this License.
59
+
60
+ “Source” form shall mean the preferred form for making modifications, including
61
+ but not limited to software source code, documentation source, and configuration
62
+ files.
63
+
64
+ “Object” form shall mean any form resulting from mechanical transformation or
65
+ translation of a Source form, including but not limited to compiled object code,
66
+ generated documentation, and conversions to other media types.
67
+
68
+ “Work” shall mean the work of authorship, whether in Source or Object form, made
69
+ available under the License, as indicated by a copyright notice that is included
70
+ in or attached to the work (an example is provided in the Appendix below).
71
+
72
+ “Derivative Works” shall mean any work, whether in Source or Object form, that
73
+ is based on (or derived from) the Work and for which the editorial revisions,
74
+ annotations, elaborations, or other modifications represent, as a whole, an
75
+ original work of authorship. For the purposes of this License, Derivative Works
76
+ shall not include works that remain separable from, or merely link (or bind by
77
+ name) to the interfaces of, the Work and Derivative Works thereof.
78
+
79
+ “Contribution” shall mean any work of authorship, including the original version
80
+ of the Work and any modifications or additions to that Work or Derivative Works
81
+ thereof, that is intentionally submitted to Licensor for inclusion in the Work
82
+ by the copyright owner or by an individual or Legal Entity authorized to submit
83
+ on behalf of the copyright owner. For the purposes of this definition,
84
+ “submitted” means any form of electronic, verbal, or written communication sent
85
+ to the Licensor or its representatives, including but not limited to
86
+ communication on electronic mailing lists, source code control systems, and
87
+ issue tracking systems that are managed by, or on behalf of, the Licensor for
88
+ the purpose of discussing and improving the Work, but excluding communication
89
+ that is conspicuously marked or otherwise designated in writing by the copyright
90
+ owner as “Not a Contribution.”
91
+
92
+ “Contributor” shall mean Licensor and any individual or Legal Entity on behalf
93
+ of whom a Contribution has been received by Licensor and subsequently
94
+ incorporated within the Work.
95
+
96
+ #### 2. Grant of Copyright License
97
+
98
+ Subject to the terms and conditions of this License, each Contributor hereby
99
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
100
+ irrevocable copyright license to reproduce, prepare Derivative Works of,
101
+ publicly display, publicly perform, sublicense, and distribute the Work and such
102
+ Derivative Works in Source or Object form.
103
+
104
+ #### 3. Grant of Patent License
105
+
106
+ Subject to the terms and conditions of this License, each Contributor hereby
107
+ grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
108
+ irrevocable (except as stated in this section) patent license to make, have
109
+ made, use, offer to sell, sell, import, and otherwise transfer the Work, where
110
+ such license applies only to those patent claims licensable by such Contributor
111
+ that are necessarily infringed by their Contribution(s) alone or by combination
112
+ of their Contribution(s) with the Work to which such Contribution(s) was
113
+ submitted. If You institute patent litigation against any entity (including a
114
+ cross-claim or counterclaim in a lawsuit) alleging that the Work or a
115
+ Contribution incorporated within the Work constitutes direct or contributory
116
+ patent infringement, then any patent licenses granted to You under this License
117
+ for that Work shall terminate as of the date such litigation is filed.
118
+
119
+ #### 4. Redistribution
120
+
121
+ You may reproduce and distribute copies of the Work or Derivative Works thereof
122
+ in any medium, with or without modifications, and in Source or Object form,
123
+ provided that You meet the following conditions:
124
+
125
+ * **(a)** You must give any other recipients of the Work or Derivative Works a copy of
126
+ this License; and
127
+ * **(b)** You must cause any modified files to carry prominent notices stating that You
128
+ changed the files; and
129
+ * **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
130
+ all copyright, patent, trademark, and attribution notices from the Source form
131
+ of the Work, excluding those notices that do not pertain to any part of the
132
+ Derivative Works; and
133
+ * **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any
134
+ Derivative Works that You distribute must include a readable copy of the
135
+ attribution notices contained within such NOTICE file, excluding those notices
136
+ that do not pertain to any part of the Derivative Works, in at least one of the
137
+ following places: within a NOTICE text file distributed as part of the
138
+ Derivative Works; within the Source form or documentation, if provided along
139
+ with the Derivative Works; or, within a display generated by the Derivative
140
+ Works, if and wherever such third-party notices normally appear. The contents of
141
+ the NOTICE file are for informational purposes only and do not modify the
142
+ License. You may add Your own attribution notices within Derivative Works that
143
+ You distribute, alongside or as an addendum to the NOTICE text from the Work,
144
+ provided that such additional attribution notices cannot be construed as
145
+ modifying the License.
146
+
147
+ You may add Your own copyright statement to Your modifications and may provide
148
+ additional or different license terms and conditions for use, reproduction, or
149
+ distribution of Your modifications, or for any such Derivative Works as a whole,
150
+ provided Your use, reproduction, and distribution of the Work otherwise complies
151
+ with the conditions stated in this License.
152
+
153
+ #### 5. Submission of Contributions
154
+
155
+ Unless You explicitly state otherwise, any Contribution intentionally submitted
156
+ for inclusion in the Work by You to the Licensor shall be under the terms and
157
+ conditions of this License, without any additional terms or conditions.
158
+ Notwithstanding the above, nothing herein shall supersede or modify the terms of
159
+ any separate license agreement you may have executed with Licensor regarding
160
+ such Contributions.
161
+
162
+ #### 6. Trademarks
163
+
164
+ This License does not grant permission to use the trade names, trademarks,
165
+ service marks, or product names of the Licensor, except as required for
166
+ reasonable and customary use in describing the origin of the Work and
167
+ reproducing the content of the NOTICE file.
168
+
169
+ #### 7. Disclaimer of Warranty
170
+
171
+ Unless required by applicable law or agreed to in writing, Licensor provides the
172
+ Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
173
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
174
+ including, without limitation, any warranties or conditions of TITLE,
175
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
176
+ solely responsible for determining the appropriateness of using or
177
+ redistributing the Work and assume any risks associated with Your exercise of
178
+ permissions under this License.
179
+
180
+ #### 8. Limitation of Liability
181
+
182
+ In no event and under no legal theory, whether in tort (including negligence),
183
+ contract, or otherwise, unless required by applicable law (such as deliberate
184
+ and grossly negligent acts) or agreed to in writing, shall any Contributor be
185
+ liable to You for damages, including any direct, indirect, special, incidental,
186
+ or consequential damages of any character arising as a result of this License or
187
+ out of the use or inability to use the Work (including but not limited to
188
+ damages for loss of goodwill, work stoppage, computer failure or malfunction, or
189
+ any and all other commercial damages or losses), even if such Contributor has
190
+ been advised of the possibility of such damages.
191
+
192
+ #### 9. Accepting Warranty or Additional Liability
193
+
194
+ While redistributing the Work or Derivative Works thereof, You may choose to
195
+ offer, and charge a fee for, acceptance of support, warranty, indemnity, or
196
+ other liability obligations and/or rights consistent with this License. However,
197
+ in accepting such obligations, You may act only on Your own behalf and on Your
198
+ sole responsibility, not on behalf of any other Contributor, and only if You
199
+ agree to indemnify, defend, and hold each Contributor harmless for any liability
200
+ incurred by, or claims asserted against, such Contributor by reason of your
201
+ accepting any such warranty or additional liability.
202
+
203
+ _END OF TERMS AND CONDITIONS_
204
+
205
+ ### APPENDIX: How to apply the Apache License to your work
206
+
207
+ To apply the Apache License to your work, attach the following boilerplate
208
+ notice, with the fields enclosed by brackets `[]` replaced with your own
209
+ identifying information. (Don't include the brackets!) The text should be
210
+ enclosed in the appropriate comment syntax for the file format. We also
211
+ recommend that a file or class name and description of purpose be included on
212
+ the same “printed page” as the copyright notice for easier identification within
213
+ third-party archives.
214
+
215
+ Copyright [yyyy] [name of copyright owner]
216
+
217
+ Licensed under the Apache License, Version 2.0 (the "License");
218
+ you may not use this file except in compliance with the License.
219
+ You may obtain a copy of the License at
220
+
221
+ http://www.apache.org/licenses/LICENSE-2.0
222
+
223
+ Unless required by applicable law or agreed to in writing, software
224
+ distributed under the License is distributed on an "AS IS" BASIS,
225
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
226
+ See the License for the specific language governing permissions and
227
+ limitations under the License.
@@ -1,75 +0,0 @@
1
- import dataclasses
2
- import functools
3
- from typing import Sequence
4
-
5
- from absl import flags
6
- from xmanager import xm
7
-
8
- from xm_slurm.executables import Dockerfile, DockerImage, ImageURI, RemoteImage
9
- from xm_slurm.executors import SlurmSpec
10
- from xm_slurm.packaging import registry
11
- from xm_slurm.packaging.docker.abc import DockerClient
12
-
13
- FLAGS = flags.FLAGS
14
- REMOTE_BUILD = flags.DEFINE_enum(
15
- "xm_builder", "local", ["local", "gcp", "azure"], "Remote build provider."
16
- )
17
-
18
- IndexedContainer = registry.IndexedContainer
19
-
20
-
21
- @functools.cache
22
- def docker_client() -> DockerClient:
23
- match REMOTE_BUILD.value:
24
- case "local":
25
- from xm_slurm.packaging.docker.local import LocalDockerClient
26
-
27
- return LocalDockerClient()
28
- case "gcp":
29
- from xm_slurm.packaging.docker.cloud import GoogleCloudRemoteDockerClient
30
-
31
- return GoogleCloudRemoteDockerClient()
32
- case "azure":
33
- raise NotImplementedError("Azure remote build is not yet supported.")
34
- case _:
35
- raise ValueError(f"Unknown remote build provider: {REMOTE_BUILD.value}")
36
-
37
-
38
- @registry.register(Dockerfile)
39
- def _(
40
- targets: Sequence[IndexedContainer[xm.Packageable]],
41
- ) -> list[IndexedContainer[RemoteImage]]:
42
- return docker_client().bake(targets=targets)
43
-
44
-
45
- @registry.register(DockerImage)
46
- def _(
47
- targets: Sequence[IndexedContainer[xm.Packageable]],
48
- ) -> list[IndexedContainer[RemoteImage]]:
49
- """Build Docker images, this is essentially a passthrough."""
50
- images = []
51
- client = docker_client()
52
- for target in targets:
53
- assert isinstance(target.value.executable_spec, DockerImage)
54
- assert isinstance(target.value.executor_spec, SlurmSpec)
55
- if target.value.executor_spec.tag is not None:
56
- raise ValueError(
57
- "Executable `DockerImage` should not be tagged via `SlurmSpec`. "
58
- "The image URI is provided by the `DockerImage` itself."
59
- )
60
-
61
- uri = ImageURI(target.value.executable_spec.image)
62
- images.append(
63
- dataclasses.replace(
64
- target,
65
- value=RemoteImage( # type: ignore
66
- image=str(uri),
67
- workdir=target.value.executable_spec.workdir,
68
- args=target.value.args,
69
- env_vars=target.value.env_vars,
70
- credentials=client.credentials(hostname=uri.domain),
71
- ),
72
- )
73
- )
74
-
75
- return images
@@ -1,112 +0,0 @@
1
- import abc
2
- import collections.abc
3
- import dataclasses
4
- import functools
5
- import os
6
- from typing import Literal, Mapping, Protocol, Sequence
7
-
8
- import jinja2 as j2
9
- from xmanager import xm
10
-
11
- from xm_slurm.executables import RemoteImage, RemoteRepositoryCredentials
12
- from xm_slurm.packaging.registry import IndexedContainer
13
-
14
-
15
- class DockerCommandProtocol(Protocol):
16
- def to_args(self) -> xm.SequentialArgs: ...
17
-
18
-
19
- @dataclasses.dataclass(frozen=True, kw_only=True)
20
- class DockerBakeCommand(DockerCommandProtocol):
21
- targets: str | Sequence[str] | None = None
22
- builder: str | None = None
23
- files: str | os.PathLike[str] | Sequence[os.PathLike[str] | str] | None = None
24
- load: bool = False
25
- cache: bool = True
26
- print: bool = False
27
- pull: bool = False
28
- push: bool = False
29
- metadata_file: str | os.PathLike[str] | None = None
30
- progress: Literal["auto", "plain", "tty"] = "auto"
31
- set: Mapping[str, str] | None = None
32
-
33
- def to_args(self) -> xm.SequentialArgs:
34
- files = self.files
35
- if files is None:
36
- files = []
37
- if not isinstance(files, collections.abc.Sequence):
38
- files = [files]
39
-
40
- targets = self.targets
41
- if targets is None:
42
- targets = []
43
- elif not isinstance(targets, collections.abc.Sequence):
44
- targets = [targets]
45
-
46
- return xm.merge_args(
47
- ["buildx", "bake"],
48
- [f"--progress={self.progress}"],
49
- [f"--builder={self.builder}"] if self.builder else [],
50
- [f"--metadata-file={self.metadata_file}"] if self.metadata_file else [],
51
- ["--print"] if self.print else [],
52
- ["--push"] if self.push else [],
53
- ["--pull"] if self.pull else [],
54
- ["--load"] if self.load else [],
55
- ["--no-cache"] if not self.cache else [],
56
- [f"--file={file}" for file in files],
57
- [f"--set={key}={value}" for key, value in self.set.items()] if self.set else [],
58
- targets,
59
- )
60
-
61
-
62
- @dataclasses.dataclass(frozen=True, kw_only=True)
63
- class DockerPullCommand(DockerCommandProtocol):
64
- image: str
65
-
66
- def to_args(self) -> xm.SequentialArgs:
67
- return xm.merge_args(["pull", self.image])
68
-
69
-
70
- @dataclasses.dataclass(frozen=True, kw_only=True)
71
- class DockerLoginCommand(DockerCommandProtocol):
72
- server: str
73
- username: str
74
- password: str | None = None
75
- password_stdin: bool = False
76
-
77
- def __post_init__(self):
78
- if self.password is None and not self.password_stdin:
79
- raise ValueError("Either password or password_stdin must be set")
80
- if self.password is not None and self.password_stdin:
81
- raise ValueError("Only one of password or password_stdin must be set")
82
-
83
- def to_args(self) -> xm.SequentialArgs:
84
- return xm.merge_args(
85
- ["login", "--username", self.username],
86
- ["--password", self.password] if self.password else [],
87
- ["--password-stdin"] if self.password_stdin else [],
88
- [self.server],
89
- )
90
-
91
-
92
- @dataclasses.dataclass(frozen=True, kw_only=True)
93
- class DockerVersionCommand(DockerCommandProtocol):
94
- def to_args(self) -> xm.SequentialArgs:
95
- return xm.merge_args(["buildx", "version"])
96
-
97
-
98
- class DockerClient(abc.ABC):
99
- @functools.cached_property
100
- def _bake_template(self) -> j2.Template:
101
- template_loader = j2.PackageLoader("xm_slurm", "templates/docker")
102
- template_env = j2.Environment(loader=template_loader, trim_blocks=True, lstrip_blocks=False)
103
-
104
- return template_env.get_template("docker-bake.hcl.j2")
105
-
106
- @abc.abstractmethod
107
- def credentials(self, *, hostname: str) -> RemoteRepositoryCredentials | None: ...
108
-
109
- @abc.abstractmethod
110
- def bake(
111
- self, *, targets: Sequence[IndexedContainer[xm.Packageable]]
112
- ) -> list[IndexedContainer[RemoteImage]]: ...