Skip to content

Adding compilation support for io_encrypt flag #393

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

Merged
merged 5 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
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
30 changes: 21 additions & 9 deletions QEfficient/cloud/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,29 @@
parser.add_argument(
"--enable_qnn",
"--enable-qnn",
action="store_true",
nargs="?",
const=True,
type=str,
default=False,
help="Enables QNN. Optionally, a configuration file can be provided with [--enable_qnn CONFIG_FILE].\
If not provided, the default configuration will be used.\
Sample Config: QEfficient/compile/qnn_config.json",
)
parser.add_argument(
"qnn_config",
nargs="?",
type=str,
)
# FIXME(ochougul): Allow extra compilation arguments
args = parser.parse_args()
QEfficient.compile(**vars(args))

args, compiler_options = parser.parse_known_args()

if isinstance(args.enable_qnn, str):
args.qnn_config = args.enable_qnn
args.enable_qnn = True

compiler_options_dict = {}
for i in range(0, len(compiler_options)):
if compiler_options[i].startswith("--"):
key = compiler_options[i].lstrip("-").replace("-", "_")
value = (
compiler_options[i + 1]
if i + 1 < len(compiler_options) and not compiler_options[i + 1].startswith("-")
else True
)
compiler_options_dict[key] = value
QEfficient.compile(**args.__dict__, **compiler_options_dict)
4 changes: 4 additions & 0 deletions QEfficient/cloud/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ def main(
**kwargs,
)

# If the io-encrypt flag is passed we will exit after QPC generation.
if kwargs.get("io_encrypt", None):
exit()

#########
# Execute
#########
Expand Down
19 changes: 15 additions & 4 deletions QEfficient/compile/compile_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ def compile_kv_model_on_cloud_ai_100(
DeprecationWarning,
stacklevel=2,
)
if kwargs:
# FIXME
raise NotImplementedError("Can't handle extra compilation args now!")
aic_binary_dir = os.path.join(base_path, "qpcs")

if os.path.isdir(aic_binary_dir):
Expand Down Expand Up @@ -111,6 +108,13 @@ def compile_kv_model_on_cloud_ai_100(
with open(mdp_ts_config_path, "w") as file:
json.dump(mdp_ts_config, file, indent=4)
command.append(f"-mdp-load-partition-config={mdp_ts_config_path}")
for key, value in kwargs.items():
option = "-" + key.replace("_", "-")
if isinstance(value, bool):
if value:
command.append(option)
continue
command.append(f"{option}={value}")
print("Running AI 100 compiler:", " ".join(command))
result = subprocess.run(command, capture_output=True, text=True)
if result.returncode != 0:
Expand Down Expand Up @@ -221,6 +225,13 @@ def compile(
allow_mxint8_mdp_io=allow_mxint8_mdp_io,
mos=mos,
device_group=device_group,
**kwargs,
)
logger.info(f"Compiled QPC files can be found here: {qpc_path}")
if kwargs.get("io_encrypt", None):
logger.warning(
f"Compilation for IO-Encrypt has been successfully completed at path: {qpc_path}. However, Efficient-Transformers do not support IO-Encrypt execution. Please run the execution separately"
)
else:
logger.info(f"Compiled QPC files can be found here: {qpc_path}")

return qpc_path
5 changes: 5 additions & 0 deletions QEfficient/transformers/models/modeling_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,11 @@ def compile(
**compiler_options,
)

if compiler_options.get("io_encrypt", None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should happen in the base class. User can pass this flag for any auto model class

logger.warning(
"Compilation for IO-Encrypt has been successfully completed. However, Efficient-Transformers do not support IO-Encrypt execution. Please run the execution separately with QPC compiled without io-encrypt."
)

return qpc_path

# FIXME: Update this method to match with transformers AutoModelForCausalLM.generate
Expand Down
Loading