|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -import os |
4 | 3 | from typing import Any, Dict, Optional, TypeVar, cast |
5 | 4 |
|
6 | | -import boto3 |
7 | 5 | import hydra |
8 | | -import wandb |
9 | | -from botocore.exceptions import ClientError, NoCredentialsError |
10 | 6 | from omegaconf import DictConfig, ListConfig, OmegaConf |
11 | 7 | from pydantic import BaseModel |
12 | 8 |
|
@@ -91,46 +87,3 @@ def config_from_path(config_path: str, overrides: Optional[DictConfig | ListConf |
91 | 87 | cfg = OmegaConf.merge(cfg, overrides) |
92 | 88 | OmegaConf.set_struct(cfg, True) |
93 | 89 | return cast(DictConfig, cfg) |
94 | | - |
95 | | - |
96 | | -def check_aws_credentials() -> bool: |
97 | | - """Check if valid AWS credentials are available from any source.""" |
98 | | - if "AWS_ACCESS_KEY_ID" in os.environ and "AWS_SECRET_ACCESS_KEY" in os.environ: |
99 | | - # This check is primarily for github actions. |
100 | | - return True |
101 | | - try: |
102 | | - sts = boto3.client("sts") |
103 | | - sts.get_caller_identity() |
104 | | - return True |
105 | | - except (NoCredentialsError, ClientError): |
106 | | - return False |
107 | | - |
108 | | - |
109 | | -def check_wandb_credentials() -> bool: |
110 | | - """Check if valid W&B credentials are available.""" |
111 | | - if "WANDB_API_KEY" in os.environ: |
112 | | - # This check is primarily for github actions. |
113 | | - return True |
114 | | - try: |
115 | | - return wandb.login(anonymous="never", timeout=10) |
116 | | - except Exception: |
117 | | - return False |
118 | | - |
119 | | - |
120 | | -def setup_metta_environment(cfg: ListConfig | DictConfig, require_aws: bool = True, require_wandb: bool = True): |
121 | | - if require_aws: |
122 | | - # Check that AWS is good to go. |
123 | | - if not check_aws_credentials(): |
124 | | - print("AWS is not configured, please install:") |
125 | | - print("brew install awscli") |
126 | | - print("and run:") |
127 | | - print("aws sso login --profile softmax") |
128 | | - print("Alternatively, set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in your environment.") |
129 | | - exit(1) |
130 | | - if cfg.wandb.enabled and require_wandb: |
131 | | - # Check that W&B is good to go. |
132 | | - if not check_wandb_credentials(): |
133 | | - print("W&B is not configured, please run:") |
134 | | - print("wandb login") |
135 | | - print("Alternatively, set WANDB_API_KEY or copy ~/.netrc from another machine that has it configured.") |
136 | | - exit(1) |
0 commit comments