Skip to content

Commit cbf5469

Browse files
committed
cleaning
1 parent 6a8f451 commit cbf5469

File tree

4 files changed

+21
-27
lines changed

4 files changed

+21
-27
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ dependencies = [
2626
'botocore>=1.31,<2',
2727
'cloudpickle>=2.1.0',
2828
'compress-pickle>=1.2.0',
29-
'google-cloud-compute>=1.40.0',
30-
'google-auth>=2.45.0',
29+
'google-cloud-compute>=1.0.0',
30+
'google-auth>=2.0.0',
3131
'humanfriendly>=10.0',
3232
"numpy>=1.22.2;python_version<'3.10'",
3333
"numpy>=1.24.0;python_version>='3.10' and python_version<'3.12'",

sdgym/_benchmark/benchmark.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,24 +98,11 @@ def _terminate_instance(compute_service):
9898
return textwrap.dedent(
9999
"""\
100100
cleanup() {
101+
log "======== Kernel messages (OOM info) =========="
102+
dmesg | tail -50 || true
101103
upload_logs || true
102-
103-
PROJECT=$(curl -sf -H "Metadata-Flavor: Google" \
104-
http://169.254.169.254/computeMetadata/v1/project/project-id || true)
105-
ZONE=$(curl -sf -H "Metadata-Flavor: Google" \
106-
http://169.254.169.254/computeMetadata/v1/instance/zone \
107-
| awk -F/ '{print $4}')
108-
NAME=$(curl -sf -H "Metadata-Flavor: Google" \
109-
http://169.254.169.254/computeMetadata/v1/instance/name)
110-
TOKEN=$(curl -sf -H "Metadata-Flavor: Google" \
111-
http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/token \
112-
| jq -r .access_token)
113-
114-
URL="https://compute.googleapis.com/compute/v1/projects/${PROJECT}/zones/${ZONE}/instances/${NAME}"
115-
curl -sf -X DELETE \
116-
-H "Authorization: Bearer ${TOKEN}" \
117-
"${URL}" >/dev/null 2>&1 || true
118-
104+
log "Shutting down GCE instance"
105+
shutdown -h now || true
119106
}
120107
"""
121108
).strip()

sdgym/benchmark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,8 +1577,8 @@ def _store_job_args_in_s3(output_destination, job_args_list, s3_client):
15771577
job_args_key = f'{path}{job_args_key}' if path else job_args_key
15781578

15791579
serialized_data = cloudpickle.dumps(job_args_list)
1580-
compressed = gzip.compress(serialized_data, compresslevel=1) # level 1 = fast
1581-
job_args_key = job_args_key + '.pkl.gz' # make it explicit
1580+
compressed = gzip.compress(serialized_data, compresslevel=1)
1581+
job_args_key = job_args_key + '.pkl.gz'
15821582
s3_client.put_object(Bucket=bucket_name, Key=job_args_key, Body=compressed)
15831583

15841584
return bucket_name, job_args_key

tests/unit/_benchmark/test_benchmark.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,31 @@ def test_make_instance_name(mock_datetime, mock_uuid):
5252

5353

5454
def test_terminate_instance_aws():
55-
"""AWS termination script uses EC2 metadata and terminate-instances."""
55+
"""AWS termination script self-terminates via EC2 metadata and AWS CLI."""
56+
# Run
5657
script = _terminate_instance('aws')
5758

59+
# Assert
5860
assert 'cleanup()' in script
61+
assert 'dmesg | tail -50' in script
5962
assert 'latest/meta-data/instance-id' in script
6063
assert 'aws ec2 terminate-instances' in script
64+
assert 'shutdown -h now' not in script
6165
assert 'compute.googleapis.com' not in script
6266

6367

6468
def test_terminate_instance_gcp():
65-
"""GCP termination script uses metadata server and Compute Engine API."""
69+
"""GCP termination script shuts down the instance locally."""
70+
# Run
6671
script = _terminate_instance('gcp')
6772

73+
# Assert
6874
assert 'cleanup()' in script
69-
assert 'Metadata-Flavor: Google' in script
70-
assert 'compute.googleapis.com/compute/v1/projects' in script
71-
assert 'terminate-instances' not in script
75+
assert 'dmesg | tail -50' in script
76+
assert 'shutdown -h now' in script
77+
assert 'aws ec2 terminate-instances' not in script
78+
assert 'compute.googleapis.com' not in script
79+
assert 'Metadata-Flavor: Google' not in script
7280

7381

7482
def test_terminate_instance_invalid_service():
@@ -147,7 +155,6 @@ def test_get_user_data_script_gcp_gpu_wait(base_credentials):
147155
assert 'nvidia-smi' in script
148156
assert 'nvidia-smi' in script
149157
assert 'cleanup()' in script
150-
assert 'compute.googleapis.com' in script
151158
assert 'Setting up swap (16G)' in script
152159
assert "print('hello')" in script
153160

0 commit comments

Comments
 (0)