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

feat: support jax backend #1671

Merged
merged 2 commits into from
Nov 23, 2024
Merged
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
16 changes: 14 additions & 2 deletions dpgen/generator/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@
"""Return the model suffix based on the backend."""
mlp_engine = jdata.get("mlp_engine", "dp")
if mlp_engine == "dp":
suffix_map = {"tensorflow": ".pb", "pytorch": ".pth"}
suffix_map = {"tensorflow": ".pb", "pytorch": ".pth", "jax": ".savedmodel"}
backend = jdata.get("train_backend", "tensorflow")
if backend in suffix_map:
suffix = suffix_map[backend]
else:
raise ValueError(
f"The backend {backend} is not available. Supported backends are: 'tensorflow', 'pytorch'."
f"The backend {backend} is not available. Supported backends are: 'tensorflow', 'pytorch', 'jax'."
)
return suffix
else:
Expand Down Expand Up @@ -766,6 +766,8 @@
# assert train_command == "dp", "The 'train_command' should be 'dp'" # the tests should be updated to run this command
if suffix == ".pth":
train_command += " --pt"
elif suffix == ".savedmodel":
train_command += " --jax"

Check warning on line 770 in dpgen/generator/run.py

View check run for this annotation

Codecov / codecov/patch

dpgen/generator/run.py#L770

Added line #L770 was not covered by tests

# paths
iter_name = make_iter_name(iter_index)
Expand Down Expand Up @@ -803,6 +805,8 @@
ckpt_suffix = ".index"
elif suffix == ".pth":
ckpt_suffix = ".pt"
elif suffix == ".savedmodel":
ckpt_suffix = ".jax"

Check warning on line 809 in dpgen/generator/run.py

View check run for this annotation

Codecov / codecov/patch

dpgen/generator/run.py#L808-L809

Added lines #L808 - L809 were not covered by tests
else:
raise RuntimeError(f"Unknown suffix {suffix}")
command = f"{{ if [ ! -f model.ckpt{ckpt_suffix} ]; then {command}{init_flag}; else {command} --restart model.ckpt; fi }}"
Expand Down Expand Up @@ -840,6 +844,10 @@
]
elif suffix == ".pth":
forward_files += [os.path.join("old", "model.ckpt.pt")]
elif suffix == ".savedmodel":
forward_files += [os.path.join("old", "model.ckpt.jax")]

Check warning on line 848 in dpgen/generator/run.py

View check run for this annotation

Codecov / codecov/patch

dpgen/generator/run.py#L847-L848

Added lines #L847 - L848 were not covered by tests
else:
raise RuntimeError(f"Unknown suffix {suffix}")

Check warning on line 850 in dpgen/generator/run.py

View check run for this annotation

Codecov / codecov/patch

dpgen/generator/run.py#L850

Added line #L850 was not covered by tests
elif training_init_frozen_model is not None or training_finetune_model is not None:
forward_files.append(os.path.join("old", f"init{suffix}"))

Expand All @@ -860,6 +868,10 @@
]
elif suffix == ".pth":
backward_files += ["model.ckpt.pt"]
elif suffix == ".savedmodel":
backward_files += ["model.ckpt.jax"]

Check warning on line 872 in dpgen/generator/run.py

View check run for this annotation

Codecov / codecov/patch

dpgen/generator/run.py#L871-L872

Added lines #L871 - L872 were not covered by tests
else:
raise RuntimeError(f"Unknown suffix {suffix}")

Check warning on line 874 in dpgen/generator/run.py

View check run for this annotation

Codecov / codecov/patch

dpgen/generator/run.py#L874

Added line #L874 was not covered by tests

if not jdata.get("one_h5", False):
init_data_sys_ = jdata["init_data_sys"]
Expand Down
Loading