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

add: ability to define arbitrary GPUs #40

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
40 changes: 36 additions & 4 deletions higgsfield/internal/cfg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import List, Optional, Union, Dict
from pathlib import Path
from importlib.machinery import SourceFileLoader
import os
Expand Down Expand Up @@ -32,10 +32,11 @@ class AppConfig:
user: str
key: str
port: int
number_of_processes_per_node: int
number_of_processes_per_node: Union[int, Dict[str, List[int]]]

def __init__(self, **kwargs):
self.__dict__.update(kwargs)

@classmethod
def from_path(cls, path: Path) -> "AppConfig":
config_path = path / "src" / "config.py"
Expand All @@ -62,7 +63,9 @@ def from_path(cls, path: Path) -> "AppConfig":
raise ValueError("Please don't use root as the user")

port = module.__dict__["HOSTS_PORT"]
number_of_processes_per_node = module.__dict__["NUMBER_OF_PROCESSES_PER_NODE"]
number_of_processes_per_node = cls._sanitize_noppn(
hosts, module.__dict__["NUMBER_OF_PROCESSES_PER_NODE"]
)

key = get_key_from_path_or_key(os.getenv("SSH_KEY"))

Expand All @@ -76,6 +79,35 @@ def from_path(cls, path: Path) -> "AppConfig":
number_of_processes_per_node=number_of_processes_per_node,
)

@classmethod
def _sanitize_noppn(
cls, hosts, number_of_processes_per_node
) -> Union[int, Dict[str, List[int]]]:
if isinstance(number_of_processes_per_node, dict):
for k, v in number_of_processes_per_node.items():
if k not in hosts:
raise ValueError(
f"Host given in NUMBER_OF_PROCESSES_PER_NODE must be present in HOSTS, got {k}"
)
if not isinstance(v, list):
raise ValueError(
f"NUMBER_OF_PROCESSES_PER_NODE should be a list of integers (gpu IDs supplied to Docker), got {v} for {k}"
)

if not isinstance(number_of_processes_per_node, dict) and not isinstance(
number_of_processes_per_node, int
):
raise ValueError(
"NUMBER_OF_PROCESSES_PER_NODE should be either a dict or an int"
)

if isinstance(number_of_processes_per_node, int):
return {
host: [i for i in range(number_of_processes_per_node)] for host in hosts
}

return number_of_processes_per_node

def get_git_origin_url(self, path) -> Optional[str]:
if self.github_repo_url is not None:
return self.github_repo_url
Expand Down Expand Up @@ -106,7 +138,7 @@ def set_git_origin_url(self, path: Path):
with open(config_path, "w") as f:
# Write back the modified lines
f.writelines(lines)

if lines[-1] != "\n":
f.write("\n")

Expand Down
3 changes: 2 additions & 1 deletion higgsfield/internal/ci/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def hosts():
def proc_per_node():
wd = wd_path()
app_config = AppConfig.from_path(wd)
click.echo(str(app_config.number_of_processes_per_node))
to_echo = json.dumps(app_config.number_of_processes_per_node)
click.echo(str(to_echo))


@click.command("get-ssh-details")
Expand Down
2 changes: 1 addition & 1 deletion higgsfield/internal/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def init(wd: Path, project_name: str):

hf_deploy_ssh_folder = Path.home() / ".ssh/higgsfield/"
hf_deploy_ssh_folder.mkdir(parents=True, exist_ok=True)
priv, pub, _ = generate_deploy_keys()
priv, pub = generate_deploy_keys()
(hf_deploy_ssh_folder / f"{project_name}-github-deploy.key").write_bytes(priv)

# set permissions to 400
Expand Down
50 changes: 25 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ HOSTS_USER = "ubuntu"
HOSTS_PORT = 22

# Number of processes per node. Depends on the amount of GPUs you have on each node.
NUM_PROCESSES = 4
NUMBER_OF_PROCESSES_PER_NODE = {
HOSTS[0]: [1, 2]
}

# You can list other environment variables here.
WAN_DB_TOKEN = os.environ.get("WAN_DB_TOKEN", None)
Expand Down