Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
arpanetus committed Mar 23, 2024
2 parents 89651c9 + 8a59834 commit 1972f36
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 30 deletions.
67 changes: 67 additions & 0 deletions NOTICES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Third-Party Licenses

### python
- **License:** [Python Software Foundation License](https://docs.python.org/3.8/license.html)
- **Version:** 3.8.13
- **Link to Source:** [https://www.python.org/]

### click
- **License:** [BSD 3-Clause License](https://opensource.org/license/bsd-3-clause/)
- **Version:** 8.1.7
- **Link to Source:** [https://github.com/pallets/click]

### pyyaml
- **License:** [MIT License](https://opensource.org/licenses/MIT)
- **Version:** 6.0.1
- **Link to Source:** [https://github.com/yaml/pyyaml]

### asyncer
- **License:** [MIT License](https://opensource.org/licenses/MIT)
- **Version:** 0.0.2
- **Link to Source:** [https://github.com/tiangolo/asyncer]

### jinja2
- **License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
- **Version:** 3.1.2
- **Link to Source:** [https://github.com/pallets/jinja]

### python-dotenv
- **License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
- **Version:** 1.0.0
- **Link to Source:** [https://github.com/theskumar/python-dotenv]

### cryptography
- **License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
- **Version:** 41.0.4
- **Link to Source:** [https://github.com/pyca/cryptography]

### asyncssh
- **License:** [Eclipse Public License 2.0](https://www.eclipse.org/legal/epl-2.0/)
- **Version:** 2.14.0
- **Link to Source:** [https://github.com/ronf/asyncssh]

### bcrypt
- **License:** [Apache License 2.0](https://opensource.org/licenses/Apache-2.0)
- **Version:** 3.1.3
- **Link to Source:** [https://github.com/pyca/bcrypt/]

### libnacl
- **License:** [Apache License 2.0](https://opensource.org/licenses/Apache-2.0)
- **Version:** 1.4.2
- **Link to Source:** [https://github.com/saltstack/libnacl]

### pyopenssl
- **License:** [Apache License 2.0](https://opensource.org/licenses/Apache-2.0)
- **Version:** 23.2.0
- **Link to Source:** [https://github.com/pyca/pyopenssl]

### libsodium
- **License:** [MIT License](https://opensource.org/licenses/MIT)
- **Version:** 2.6.1
- **Link to Source:** [https://github.com/libsodiumproject/sodium]

### invoker
- **License:** [Apache License 2.0](https://opensource.org/licenses/Apache-2.0)
- **Version:** latest
- **Link to Source:** [https://github.com/higgsfield-ai/invoker]

13 changes: 12 additions & 1 deletion higgsfield/internal/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@ class AppConfig:
user: str
key: str
port: int
master_host: Optional[str]
no_python: Optional[str]
invoker_exec: str = "invoker"
number_of_processes_per_node: int

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

@classmethod
def from_path(cls, path: Path) -> "AppConfig":
config_path = path / "src" / "config.py"
Expand Down Expand Up @@ -66,6 +70,10 @@ def from_path(cls, path: Path) -> "AppConfig":

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

master_host = module.__dict__.get("MASTER_HOST", None)
no_python = module.__dict__.get("NO_PYTHON", None)
invoker_exec = module.__dict__.get("INVOKER_EXEC", "invoker")

return AppConfig(
name=name,
github_repo_url=github_repo_url,
Expand All @@ -74,6 +82,9 @@ def from_path(cls, path: Path) -> "AppConfig":
key=key,
port=port,
number_of_processes_per_node=number_of_processes_per_node,
master_host=master_host,
no_python=no_python,
invoker_exec=invoker_exec,
)

def get_git_origin_url(self, path) -> Optional[str]:
Expand Down Expand Up @@ -106,7 +117,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
24 changes: 22 additions & 2 deletions higgsfield/internal/experiment/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ def generate(self):
class ExperimentBuilder(ActionBuilder):
template_name = "experiment_action.j2"

def of_master_host(self) -> str:
master_host = self.app_config.master_host
if master_host is None:
return ""
return f"--master_host {master_host}"

def of_no_python(self) -> str:
no_python = self.app_config.no_python
if no_python is None:
return ""
return f"--no_python {no_python}"

def generate(self, experiment_name: str, params: List[Param]):
(self.wf_dir / f"run_{experiment_name}.yml").write_text(
self.template.render(
Expand All @@ -113,12 +125,14 @@ def generate(self, experiment_name: str, params: List[Param]):
project_name=self.app_config.name,
params=build_gh_action_inputs(params),
rest=build_run_params(params),
invoker_exec=self.app_config.invoker_exec,
of_master_host=self.of_master_host(),
of_no_python=self.of_no_python(),
env_gen=env_keys_as_action(
self.wf_dir.parent.parent / "env", echo_indent
),
)
)


print("Updated experiment action", experiment_name)

Expand All @@ -130,7 +144,13 @@ def _source_experiments(base_path: Path):
the same dependencies (aka environment) as the docker container.
"""
for file in base_path.glob("**/*.py"):
module_name = os.path.basename(file).split(".py")[0].split(".py")[0].replace(" ", "_").replace("-", "_")
module_name = (
os.path.basename(file)
.split(".py")[0]
.split(".py")[0]
.replace(" ", "_")
.replace("-", "_")
)
SourceFileLoader(module_name, str(file)).load_module()


Expand Down
6 changes: 3 additions & 3 deletions higgsfield/internal/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ def generate_deploy_keys() -> Tuple[bytes, bytes]:

private_bytes = private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.PKCS8,
format=serialization.PrivateFormat.OpenSSH,
encryption_algorithm=serialization.NoEncryption(),
)

public_bytes = public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo,
encoding=serialization.Encoding.OpenSSH,
format=serialization.PublicFormat.OpenSSH,
)

return private_bytes, public_bytes
4 changes: 2 additions & 2 deletions higgsfield/internal/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@


def check_name(name: str):
if len(name) < 1 or len(name) > 20:
raise ValueError("Name must be between 1 and 20 characters long")
if len(name) < 1 or len(name) > 30:
raise ValueError("Name must be between 1 and 30 characters long")

if not regex.match(name):
raise ValueError("Name must match regex ^[a-zA-Z_][a-zA-Z0-9_]*$")
Expand Down
8 changes: 4 additions & 4 deletions higgsfield/llama/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ def __init__(
if not checkpoint_path:
if cpu_init_rank0:
if rank == 0:
model = LlamaForCausalLM.from_pretrained(model_name)
model = LlamaForCausalLM.from_pretrained(model_name, use_cache=False)
else:
llama_config = LlamaConfig.from_pretrained(model_name)
llama_config = LlamaConfig.from_pretrained(model_name, use_cache=False)

with torch.device('meta'):
model = LlamaForCausalLM(llama_config)
else:
model = LlamaForCausalLM.from_pretrained(model_name)
model = LlamaForCausalLM.from_pretrained(model_name, use_cache=False)
else:
if not cpu_init_rank0:
print("Ignoring cpu_init_rank0=False while loading model from checkpoint path")
Expand Down Expand Up @@ -298,4 +298,4 @@ def __init__(
precision,
cpu_init_rank0,
cpu_offload,
)
)
4 changes: 2 additions & 2 deletions higgsfield/static/templates/deploy_action.j2
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ jobs:
host: ${{ env.HOSTS }}
username: ${{ env.USER }}
key: ${{ secrets.SSH_KEY }}
port: ${{ env.PORT }}
sync: true {% endraw %}
port: ${{ env.PORT }} {% endraw %}
script: |
mkdir -p ~/higgsfield/
cd ~/higgsfield
Expand All @@ -48,5 +47,6 @@ jobs:
git reset --hard origin/main && \
git pull origin main) || git clone {{ keyed_repo_url }} {{ project_name }} || rm -rf ~/higgsfield/{{ project_name }} && git clone {{ keyed_repo_url }} {{ project_name }}

cd ~/higgsfield/{{ project_name }}
echo "SSH_KEY=NOTHING" > env
{{ env_gen }}
2 changes: 1 addition & 1 deletion higgsfield/static/templates/experiment_action.j2
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
cd ~/higgsfield/{% endraw %}{{ project_name }}
echo "SSH_KEY=NOTHING" > env
{{ env_gen }}
invoker experiment run --project_name {{ project_name }} --experiment_name {{ experiment_name }} {% raw %} --run_name ${{ env.RUN_NAME }} --port ${{ env.RUN_PORT }} --nproc_per_node ${{ env.NPROC_PER_NODE }} --hosts ${{ env.HOSTS }} {% endraw %} {{ rest }}
{{ invoker_exec }} experiment run {{ of_master_host }} {{ of_no_python }} --project_name {{ project_name }} --experiment_name {{ experiment_name }} {% raw %} --run_name ${{ env.RUN_NAME }} --port ${{ env.RUN_PORT }} --nproc_per_node ${{ env.NPROC_PER_NODE }} --hosts ${{ env.HOSTS }} {% endraw %} {{ rest }}



13 changes: 1 addition & 12 deletions poetry.lock

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

4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ pyyaml = "^6.0.1"
asyncer = "^0.0.2"
jinja2 = "^3.1.2"
python-dotenv = "^1.0.0"
unidecode = "^1.3.7"
cryptography = "^41.0.4"
asyncssh = {extras = ["bcrypt", "fido2", "libnacl", "pyopenssl"], version = "^2.14.0"}
asyncssh = {extras = ["bcrypt", "libnacl", "pyopenssl"], version = "^2.14.0"}
bcrypt = "^4.0.1"
fido2 = "^1.1.2"
libsodium = "^2.6.1"
pyopenssl = "^23.2.0"

Expand Down

0 comments on commit 1972f36

Please sign in to comment.