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 1 commit
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 @@ def _get_model_suffix(jdata) -> str:
"""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 @@ def run_train_dp(iter_index, jdata, mdata):
# 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"
njzjz marked this conversation as resolved.
Show resolved Hide resolved

# paths
iter_name = make_iter_name(iter_index)
Expand Down Expand Up @@ -803,6 +805,8 @@ def run_train_dp(iter_index, jdata, mdata):
ckpt_suffix = ".index"
elif suffix == ".pth":
ckpt_suffix = ".pt"
elif suffix == ".savedmodel":
ckpt_suffix = ".jax"
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 @@ def run_train_dp(iter_index, jdata, mdata):
]
elif suffix == ".pth":
forward_files += [os.path.join("old", "model.ckpt.pt")]
elif suffix == ".savedmodel":
forward_files += [os.path.join("old", "model.ckpt.jax")]
else:
raise RuntimeError(f"Unknown suffix {suffix}")
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 @@ def run_train_dp(iter_index, jdata, mdata):
]
elif suffix == ".pth":
backward_files += ["model.ckpt.pt"]
elif suffix == ".savedmodel":
backward_files += ["model.ckpt.jax"]
else:
raise RuntimeError(f"Unknown suffix {suffix}")

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