-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Refactor post-processing of adapters (#345)
* refactor saving tokens metadata Signed-off-by: Sukriti-Sharma4 <[email protected]> * remove extra check Signed-off-by: Sukriti-Sharma4 <[email protected]> * post processing script Signed-off-by: Sukriti-Sharma4 <[email protected]> * post processing script Signed-off-by: Sukriti-Sharma4 <[email protected]> * fix: unit test args Signed-off-by: Sukriti-Sharma4 <[email protected]> * undo post_process_vLLm flag Signed-off-by: Sukriti-Sharma4 <[email protected]> --------- Signed-off-by: Sukriti-Sharma4 <[email protected]>
- Loading branch information
Showing
7 changed files
with
106 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Standard | ||
import argparse | ||
import json | ||
import os | ||
|
||
# Local | ||
from tuning.utils.merge_model_utils import post_process_vLLM_adapters_new_tokens | ||
|
||
|
||
### Main & arg parsing | ||
def main(): | ||
parser = argparse.ArgumentParser( | ||
description="Post processes adapters due to addition of new tokens, as needed by vLLM" | ||
) | ||
parser.add_argument( | ||
"--model_path", | ||
help="Path to tuned model containing either one or multiple checkpoints \ | ||
Path should have file added_tokens_info.json produced by tuning \ | ||
Hint: This will be either output_dir or save_model_dir arguments while tuning \ | ||
If multiple checkpoints are present, each checkpoint folder name \ | ||
should begin with 'checkpoint-'", | ||
required=True, | ||
) | ||
parser.add_argument( | ||
"--output_model_path", | ||
help="Output directory where post-processed artifacts will be stored. \ | ||
If not provided, artifacts will be modified in place", | ||
default=None, | ||
) | ||
args = parser.parse_args() | ||
|
||
if os.path.exists(os.path.join(args.model_path, "added_tokens_info.json")): | ||
with open( | ||
os.path.join(args.model_path, "added_tokens_info.json"), encoding="utf-8" | ||
) as json_data: | ||
added_tokens_info = json.loads(json_data) | ||
num_added_tokens = added_tokens_info["num_added_tokens"] | ||
else: | ||
print("file added_tokens_info.json not in model_path. Cannot post-processes") | ||
|
||
if os.path.exists(os.path.join(args.model_path, "adapter_model.safetensors")): | ||
post_process_vLLM_adapters_new_tokens( | ||
args.model_path, args.output_model_path, num_added_tokens | ||
) | ||
# if multiple checkpoints in directory, process each checkpoint | ||
for _, dirs, _ in os.walk(args.model_path, topdown=False): | ||
for name in dirs: | ||
if "checkpoint-" in name.lower(): | ||
post_process_vLLM_adapters_new_tokens( | ||
os.path.join(args.model_path, name), | ||
os.path.join(args.output_model_path, name), | ||
num_added_tokens, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters