Skip to content

Commit 4da283e

Browse files
authored
Adding compilation support for io_encrypt flag (#393)
As part of Model-IP I/O encryption feature qaic-exec has added a new command line option: `-io-encrypt` to enable support for decryption/encryption of network I/O. Added support in Qeff to pass this param to qaic-exec when a model needs to be compiled with I/O encryption support. CLI command: `python -m QEfficient.cloud.infer --model_name gpt2 --batch_size 1 --prompt_len 32 --ctx_len 128 --mxfp6 --num_cores 16 --device_group [0] --prompt "My name is" --mos 1 --aic_enable_depth_first --io-encrypt "chacha20"` Note: If the flag is passed via infer CLI, CLI will exit after QPC generation. --------- Signed-off-by: Asmita Goswami <[email protected]>
1 parent 4e5c95a commit 4da283e

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

QEfficient/cloud/compile.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,29 @@
8585
parser.add_argument(
8686
"--enable_qnn",
8787
"--enable-qnn",
88-
action="store_true",
88+
nargs="?",
89+
const=True,
90+
type=str,
8991
default=False,
9092
help="Enables QNN. Optionally, a configuration file can be provided with [--enable_qnn CONFIG_FILE].\
9193
If not provided, the default configuration will be used.\
9294
Sample Config: QEfficient/compile/qnn_config.json",
9395
)
94-
parser.add_argument(
95-
"qnn_config",
96-
nargs="?",
97-
type=str,
98-
)
99-
# FIXME(ochougul): Allow extra compilation arguments
100-
args = parser.parse_args()
101-
QEfficient.compile(**vars(args))
96+
97+
args, compiler_options = parser.parse_known_args()
98+
99+
if isinstance(args.enable_qnn, str):
100+
args.qnn_config = args.enable_qnn
101+
args.enable_qnn = True
102+
103+
compiler_options_dict = {}
104+
for i in range(0, len(compiler_options)):
105+
if compiler_options[i].startswith("--"):
106+
key = compiler_options[i].lstrip("-").replace("-", "_")
107+
value = (
108+
compiler_options[i + 1]
109+
if i + 1 < len(compiler_options) and not compiler_options[i + 1].startswith("-")
110+
else True
111+
)
112+
compiler_options_dict[key] = value
113+
QEfficient.compile(**args.__dict__, **compiler_options_dict)

QEfficient/cloud/infer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ def main(
197197
**kwargs,
198198
)
199199

200+
# If the io-encrypt flag is passed we will exit after QPC generation.
201+
if kwargs.get("io_encrypt", None):
202+
exit()
203+
200204
#########
201205
# Execute
202206
#########

QEfficient/compile/compile_helper.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ def compile_kv_model_on_cloud_ai_100(
6464
DeprecationWarning,
6565
stacklevel=2,
6666
)
67-
if kwargs:
68-
# FIXME
69-
raise NotImplementedError("Can't handle extra compilation args now!")
7067
aic_binary_dir = os.path.join(base_path, "qpcs")
7168

7269
if os.path.isdir(aic_binary_dir):
@@ -111,6 +108,13 @@ def compile_kv_model_on_cloud_ai_100(
111108
with open(mdp_ts_config_path, "w") as file:
112109
json.dump(mdp_ts_config, file, indent=4)
113110
command.append(f"-mdp-load-partition-config={mdp_ts_config_path}")
111+
for key, value in kwargs.items():
112+
option = "-" + key.replace("_", "-")
113+
if isinstance(value, bool):
114+
if value:
115+
command.append(option)
116+
continue
117+
command.append(f"{option}={value}")
114118
print("Running AI 100 compiler:", " ".join(command))
115119
result = subprocess.run(command, capture_output=True, text=True)
116120
if result.returncode != 0:
@@ -221,6 +225,13 @@ def compile(
221225
allow_mxint8_mdp_io=allow_mxint8_mdp_io,
222226
mos=mos,
223227
device_group=device_group,
228+
**kwargs,
224229
)
225-
logger.info(f"Compiled QPC files can be found here: {qpc_path}")
230+
if kwargs.get("io_encrypt", None):
231+
logger.warning(
232+
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"
233+
)
234+
else:
235+
logger.info(f"Compiled QPC files can be found here: {qpc_path}")
236+
226237
return qpc_path

QEfficient/transformers/models/modeling_auto.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,11 @@ def compile(
16351635
**compiler_options,
16361636
)
16371637

1638+
if compiler_options.get("io_encrypt", None):
1639+
logger.warning(
1640+
"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."
1641+
)
1642+
16381643
return qpc_path
16391644

16401645
# FIXME: Update this method to match with transformers AutoModelForCausalLM.generate

0 commit comments

Comments
 (0)