Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update spec format to include arch #120

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Given a spec, the API will calculate the optimal resource allocation for the job
The spec sent to the endpoint should have the following format:

```
pkg_name@pkg_version +variant1+variant2%compiler@compiler_version
pkg_name@pkg_version +variant1+variant2 arch=arch%compiler@compiler_version
```

Be sure that the string is URL-encoded. For instance, the `urllib.parse.quote` method will ensure the proper format. Without it, the allocation algorithm may return inaccurate results.
Expand Down
6 changes: 3 additions & 3 deletions gantry/tests/defs/prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
from gantry.util.spec import parse_alloc_spec

NORMAL_BUILD = parse_alloc_spec(
"[email protected] ~caffe2+cuda+cudnn~debug+distributed+fbgemm+gloo+kineto~magma~metal+mkldnn+mpi~nccl+nnpack+numa+numpy+onnx_ml+openmp+qnnpack~rocm+tensorpipe~test+valgrind+xnnpack build_system=python_pip cuda_arch=80%[email protected]"
"[email protected] ~caffe2+cuda+cudnn~debug+distributed+fbgemm+gloo+kineto~magma~metal+mkldnn+mpi~nccl+nnpack+numa+numpy+onnx_ml+openmp+qnnpack~rocm+tensorpipe~test+valgrind+xnnpack build_system=python_pip cuda_arch=80 arch=x86_64%[email protected]"
)

# everything in NORMAL_BUILD["package"]["variants"] except removing build_system=python_pip
# in order to test the expensive variants filter
EXPENSIVE_VARIANT_BUILD = parse_alloc_spec(
"[email protected] ~caffe2+cuda+cudnn~debug+distributed+fbgemm+gloo+kineto~magma~metal+mkldnn+mpi~nccl+nnpack+numa+numpy+onnx_ml+openmp+qnnpack~rocm+tensorpipe~test+valgrind+xnnpack cuda_arch=80%[email protected]"
"[email protected] ~caffe2+cuda+cudnn~debug+distributed+fbgemm+gloo+kineto~magma~metal+mkldnn+mpi~nccl+nnpack+numa+numpy+onnx_ml+openmp+qnnpack~rocm+tensorpipe~test+valgrind+xnnpack cuda_arch=80 arch=x86_64%[email protected]"
)

# no variants should match this, so we expect the default prediction
BAD_VARIANT_BUILD = parse_alloc_spec(
"[email protected] +no~expensive~variants+match%[email protected]"
"[email protected] +no~expensive~variants+match arch=x86_64%[email protected]"
)

# calculated by running the baseline prediction algorithm on the sample data in gantry/tests/sql/insert_prediction.sql
Expand Down
5 changes: 4 additions & 1 deletion gantry/tests/test_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ async def test_empty_sample(db_conn):
# Test validate_payload
def test_valid_spec():
"""Tests that a valid spec is parsed correctly."""
assert parse_alloc_spec("[email protected] +json+native+treesitter%[email protected]") == {
assert parse_alloc_spec(
"[email protected] +json+native+treesitter arch=x86_64%[email protected]"
) == {
"pkg_name": "emacs",
"pkg_version": "29.2-test",
"pkg_variants": '{"json": true, "native": true, "treesitter": true}',
"pkg_variants_dict": {"json": True, "native": True, "treesitter": True},
"compiler_name": "gcc",
"compiler_version": "12.3.0",
"arch": "x86_64",
}


Expand Down
7 changes: 5 additions & 2 deletions gantry/util/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ def parse_alloc_spec(spec: str) -> dict:
- pkg_variants_dict: dict
- compiler: str
- compiler_version: str
- arch: str

Returns an empty dict if the spec is invalid.

This format is specifically used for the allocation API and is documented
for the client.
"""

# example: [email protected] +json+native+treesitter%[email protected]
# example: [email protected] +json+native+treesitter arch=x86_64%[email protected]
# this regex accommodates versions made up of any non-space characters
spec_pattern = re.compile(r"(.+?)@(\S+)\s+(.+?)%([\w-]+)@(\S+)")
spec_pattern = re.compile(r"(.+?)@(\S+)\s+(.+?)\s+arch=(\S+)%([\w-]+)@(\S+)")

match = spec_pattern.match(spec)
if not match:
Expand All @@ -64,6 +65,7 @@ def parse_alloc_spec(spec: str) -> dict:
pkg_name,
pkg_version,
pkg_variants,
arch,
compiler_name,
compiler_version,
) = match.groups()
Expand All @@ -83,6 +85,7 @@ def parse_alloc_spec(spec: str) -> dict:
"pkg_variants_dict": pkg_variants_dict,
"compiler_name": compiler_name,
"compiler_version": compiler_version,
"arch": arch,
}

return spec_dict
2 changes: 1 addition & 1 deletion gantry/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def allocation(request: web.Request) -> web.Response:
that set resource allocations based on historical data.

acceptable spec format:
pkg_name@pkg_version +variant1+variant2%compiler@compiler_version
pkg_name@pkg_version +variant1+variant2%compiler arch=arch@compiler_version
NOTE: there must be a space between the package version and the variants

returns:
Expand Down