Skip to content

Commit

Permalink
Update on "[ET] Include delegate debug data in tsv"
Browse files Browse the repository at this point in the history
to follow the signature of `print_data_tabular`.

Differential Revision: [D68534947](https://our.internmc.facebook.com/intern/diff/D68534947/)

[ghstack-poisoned]
  • Loading branch information
jorgep31415 committed Jan 23, 2025
2 parents 35008cd + 9d46e90 commit fef6f33
Show file tree
Hide file tree
Showing 67 changed files with 1,547 additions and 533 deletions.
Empty file added .ci/scripts/__init__.py
Empty file.
145 changes: 104 additions & 41 deletions .ci/scripts/gather_benchmark_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import logging
import os
import re
from typing import Any, Dict
import sys
from typing import Any, Dict, List

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
from examples.models import MODEL_NAME_TO_MODEL


Expand Down Expand Up @@ -45,6 +47,79 @@
}


def extract_all_configs(data, target_os=None):
if isinstance(data, dict):
# If target_os is specified, include "xplat" and the specified branch
include_branches = {"xplat", target_os} if target_os else data.keys()
return [
v
for key, value in data.items()
if key in include_branches
for v in extract_all_configs(value, target_os)
]
elif isinstance(data, list):
return [v for item in data for v in extract_all_configs(item, target_os)]
else:
return [data]


def generate_compatible_configs(model_name: str, target_os=None) -> List[str]:
"""
Generate a list of compatible benchmark configurations for a given model name and target OS.
Args:
model_name (str): The name of the model to generate configurations for.
target_os (Optional[str]): The target operating system (e.g., 'android', 'ios').
Returns:
List[str]: A list of compatible benchmark configurations.
Raises:
None
Example:
generate_compatible_configs('meta-llama/Llama-3.2-1B', 'ios') -> ['llama3_fb16', 'llama3_coreml_ane']
"""
configs = []
if is_valid_huggingface_model_id(model_name):
if model_name.startswith("meta-llama/"):
# LLaMA models
repo_name = model_name.split("meta-llama/")[1]
if "qlora" in repo_name.lower():
configs.append("llama3_qlora")
elif "spinquant" in repo_name.lower():
configs.append("llama3_spinquant")
else:
configs.append("llama3_fb16")
configs.extend(
[
config
for config in BENCHMARK_CONFIGS.get(target_os, [])
if config.startswith("llama")
]
)
else:
# Non-LLaMA models
configs.append("hf_xnnpack_fp32")
elif model_name in MODEL_NAME_TO_MODEL:
# ExecuTorch in-tree non-GenAI models
configs.append("xnnpack_q8")
if target_os != "xplat":
# Add OS-specific configs
configs.extend(
[
config
for config in BENCHMARK_CONFIGS.get(target_os, [])
if not config.startswith("llama")
]
)
else:
# Skip unknown models with a warning
logging.warning(f"Unknown or invalid model name '{model_name}'. Skipping.")

return configs


def parse_args() -> Any:
"""
Parse command-line arguments.
Expand Down Expand Up @@ -82,6 +157,11 @@ def comma_separated(value: str):
type=comma_separated, # Use the custom parser for comma-separated values
help=f"Comma-separated device names. Available devices: {list(DEVICE_POOLS.keys())}",
)
parser.add_argument(
"--configs",
type=comma_separated, # Use the custom parser for comma-separated values
help=f"Comma-separated benchmark configs. Available configs: {extract_all_configs(BENCHMARK_CONFIGS)}",
)

return parser.parse_args()

Expand All @@ -98,11 +178,16 @@ def set_output(name: str, val: Any) -> None:
set_output("benchmark_configs", {"include": [...]})
"""

if os.getenv("GITHUB_OUTPUT"):
print(f"Setting {val} to GitHub output")
with open(str(os.getenv("GITHUB_OUTPUT")), "a") as env:
print(f"{name}={val}", file=env)
else:
github_output = os.getenv("GITHUB_OUTPUT")
if not github_output:
print(f"::set-output name={name}::{val}")
return

try:
with open(github_output, "a") as env:
env.write(f"{name}={val}\n")
except PermissionError:
# Fall back to printing in case of permission error in unit tests
print(f"::set-output name={name}::{val}")


Expand All @@ -123,7 +208,7 @@ def is_valid_huggingface_model_id(model_name: str) -> bool:
return bool(re.match(pattern, model_name))


def get_benchmark_configs() -> Dict[str, Dict]:
def get_benchmark_configs() -> Dict[str, Dict]: # noqa: C901
"""
Gather benchmark configurations for a given set of models on the target operating system and devices.
Expand Down Expand Up @@ -153,48 +238,26 @@ def get_benchmark_configs() -> Dict[str, Dict]:
}
"""
args = parse_args()
target_os = args.os
devices = args.devices
models = args.models
target_os = args.os
target_configs = args.configs

benchmark_configs = {"include": []}

for model_name in models:
configs = []
if is_valid_huggingface_model_id(model_name):
if model_name.startswith("meta-llama/"):
# LLaMA models
repo_name = model_name.split("meta-llama/")[1]
if "qlora" in repo_name.lower():
configs.append("llama3_qlora")
elif "spinquant" in repo_name.lower():
configs.append("llama3_spinquant")
else:
configs.append("llama3_fb16")
configs.extend(
[
config
for config in BENCHMARK_CONFIGS.get(target_os, [])
if config.startswith("llama")
]
configs.extend(generate_compatible_configs(model_name, target_os))
print(f"Discovered all supported configs for model '{model_name}': {configs}")
if target_configs is not None:
for config in target_configs:
if config not in configs:
raise Exception(
f"Unsupported config '{config}' for model '{model_name}' on '{target_os}'. Skipped.\n"
f"Supported configs are: {configs}"
)
else:
# Non-LLaMA models
configs.append("hf_xnnpack_fp32")
elif model_name in MODEL_NAME_TO_MODEL:
# ExecuTorch in-tree non-GenAI models
configs.append("xnnpack_q8")
configs.extend(
[
config
for config in BENCHMARK_CONFIGS.get(target_os, [])
if not config.startswith("llama")
]
)
else:
# Skip unknown models with a warning
logging.warning(f"Unknown or invalid model name '{model_name}'. Skipping.")
continue
configs = target_configs
print(f"Using provided configs {configs} for model '{model_name}'")

# Add configurations for each valid device
for device in devices:
Expand Down
2 changes: 2 additions & 0 deletions .ci/scripts/test_llama.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ fi

if [[ "${MODE}" =~ .*quantize_kv.* ]]; then
QUANTIZE_KV_CACHE=ON
# quantize_kv cache transform uses custom kv cache update op
CUSTOM=ON
else
QUANTIZE_KV_CACHE=OFF
fi
Expand Down
7 changes: 7 additions & 0 deletions .ci/scripts/test_model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ test_model_with_qnn() {
EXPORT_SCRIPT=inception_v3
elif [[ "${MODEL_NAME}" == "vit" ]]; then
EXPORT_SCRIPT=torchvision_vit
elif [[ "${MODEL_NAME}" == "edsr" ]]; then
EXPORT_SCRIPT=edsr
# Additional deps for edsr
pip install piq
else
echo "Unsupported model $MODEL_NAME"
exit 1
fi

# Use SM8450 for S22, SM8550 for S23, and SM8560 for S24
Expand Down
Loading

0 comments on commit fef6f33

Please sign in to comment.