Upload gen_models--microsoft--Phi-3.5-mini-instruct.py with huggingface_hub
Browse files
gen_models--microsoft--Phi-3.5-mini-instruct.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#**************************************************************************
|
| 2 |
+
#|| SiMa.ai CONFIDENTIAL ||
|
| 3 |
+
#|| Unpublished Copyright (c) 2025 SiMa.ai, All Rights Reserved. ||
|
| 4 |
+
#**************************************************************************
|
| 5 |
+
# NOTICE: All information contained herein is, and remains the property of
|
| 6 |
+
# SiMa.ai. The intellectual and technical concepts contained herein are
|
| 7 |
+
# proprietary to SiMa and may be covered by U.S. and Foreign Patents,
|
| 8 |
+
# patents in process, and are protected by trade secret or copyright law.
|
| 9 |
+
#
|
| 10 |
+
# Dissemination of this information or reproduction of this material is
|
| 11 |
+
# strictly forbidden unless prior written permission is obtained from
|
| 12 |
+
# SiMa.ai. Access to the source code contained herein is hereby forbidden
|
| 13 |
+
# to anyone except current SiMa.ai employees, managers or contractors who
|
| 14 |
+
# have executed Confidentiality and Non-disclosure agreements explicitly
|
| 15 |
+
# covering such access.
|
| 16 |
+
#
|
| 17 |
+
# The copyright notice above does not evidence any actual or intended
|
| 18 |
+
# publication or disclosure of this source code, which includes information
|
| 19 |
+
# that is confidential and/or proprietary, and is a trade secret, of SiMa.ai.
|
| 20 |
+
#
|
| 21 |
+
# ANY REPRODUCTION, MODIFICATION, DISTRIBUTION, PUBLIC PERFORMANCE, OR PUBLIC
|
| 22 |
+
# DISPLAY OF OR THROUGH USE OF THIS SOURCE CODE WITHOUT THE EXPRESS WRITTEN
|
| 23 |
+
# CONSENT OF SiMa.ai IS STRICTLY PROHIBITED, AND IN VIOLATION OF APPLICABLE
|
| 24 |
+
# LAWS AND INTERNATIONAL TREATIES. THE RECEIPT OR POSSESSION OF THIS SOURCE
|
| 25 |
+
# CODE AND/OR RELATED INFORMATION DOES NOT CONVEY OR IMPLY ANY RIGHTS TO
|
| 26 |
+
# REPRODUCE, DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR TO MANUFACTURE, USE, OR
|
| 27 |
+
# SELL ANYTHING THAT IT MAY DESCRIBE, IN WHOLE OR IN PART.
|
| 28 |
+
#
|
| 29 |
+
#**************************************************************************
|
| 30 |
+
|
| 31 |
+
import logging
|
| 32 |
+
|
| 33 |
+
from pathlib import Path
|
| 34 |
+
|
| 35 |
+
from afe.apis.error_handling_variables import enable_verbose_error_messages
|
| 36 |
+
from sima_utils.transformer.model import FileGenMode, FileGenPrecision, VisionLanguageModel
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def gen_files(model_path: Path, num_processes: int, resume: bool):
|
| 40 |
+
enable_verbose_error_messages()
|
| 41 |
+
|
| 42 |
+
max_num_tokens = 1024
|
| 43 |
+
language_group_size = 128
|
| 44 |
+
language_group_offsets = list(
|
| 45 |
+
range(0, max_num_tokens - language_group_size + 1, language_group_size)
|
| 46 |
+
)
|
| 47 |
+
language_future_token_mask_size = 128
|
| 48 |
+
|
| 49 |
+
model = VisionLanguageModel.from_hf_cache(
|
| 50 |
+
hf_cache_path=model_path,
|
| 51 |
+
model_name=model_path.name,
|
| 52 |
+
onnx_path=Path(f"{model_path.name}/onnx_files"),
|
| 53 |
+
sima_path=Path(f"{model_path.name}/sima_files"),
|
| 54 |
+
max_num_tokens=max_num_tokens,
|
| 55 |
+
system_prompt=None,
|
| 56 |
+
override_language_group_size=language_group_size,
|
| 57 |
+
override_language_group_offsets=language_group_offsets,
|
| 58 |
+
override_language_future_token_mask_size=language_future_token_mask_size,
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
# Update the eos token ids to avoid repeating answers.
|
| 62 |
+
model.cfg.update_special_tokens({"eos_token_id": [32000, 32001, 32007]})
|
| 63 |
+
|
| 64 |
+
log_level = logging.INFO
|
| 65 |
+
precision = {
|
| 66 |
+
"language": FileGenPrecision.BF16,
|
| 67 |
+
"group": FileGenPrecision.BF16,
|
| 68 |
+
"single": FileGenPrecision.A_BF16_W_INT4,
|
| 69 |
+
}
|
| 70 |
+
model.gen_files(
|
| 71 |
+
FileGenMode.ALL, precision=precision, log_level=log_level, num_processes=num_processes,
|
| 72 |
+
resume=resume
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
if __name__ == "__main__":
|
| 76 |
+
import argparse
|
| 77 |
+
|
| 78 |
+
# Download the HuggingFace microsoft/Phi-3.5-mini-instruct using the following command.
|
| 79 |
+
# huggingface-cli download microsoft/Phi-3.5-mini-instruct
|
| 80 |
+
|
| 81 |
+
parser = argparse.ArgumentParser(description="VLM generate file arguments")
|
| 82 |
+
parser.add_argument("--model_path", type=Path, required=True)
|
| 83 |
+
parser.add_argument("--num_processes", type=int, default=1)
|
| 84 |
+
parser.add_argument("--resume", action="store_true", default=False)
|
| 85 |
+
args = parser.parse_args()
|
| 86 |
+
print("Arguments:", args, flush=True)
|
| 87 |
+
gen_files(args.model_path, args.num_processes, args.resume)
|