Skip to content

Commit 2639652

Browse files
committed
[Neo] Change Neo output file format
Changes the Neo output file format to better support requirements.txt and custom entry point files. The compiler output will be saved to a subdirectory and the input files are copied over to the output.
1 parent 36810cc commit 2639652

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

serving/docker/partition/sm_neo_neuron_partition.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
PYTHON_CACHE_DIR = '/tmp/djlserving/cache'
3333
_neuronxcc_version: Optional[str] = None
34+
NEO_OPTIMIZED_MODEL_DIR = 'neo_optimized_model'
3435

3536

3637
def get_neuronxcc_version() -> str:
@@ -401,13 +402,35 @@ def write_properties(self) -> str:
401402
self.properties_manager.properties = output_properties
402403
self.properties_manager.generate_properties_file()
403404

405+
output_passthrough_properties[
406+
"option.model_id"] = f"./{NEO_OPTIMIZED_MODEL_DIR}"
404407
# Write out pass-through properties
405408
properties_file = os.path.join(self.OUTPUT_MODEL_DIRECTORY,
406409
'serving.properties')
407410
with open(properties_file, "a") as f:
408411
for k, v in output_passthrough_properties.items():
409412
f.write(f"{k}={v}\n")
410413

414+
def copy_input_files_to_output(self):
415+
"""
416+
Copies inputted files to output so that custom entrypoints or requirements files are preserved.
417+
418+
TODO: Avoid making redundant copies of model weights.
419+
"""
420+
# move outputted files to subdirectory
421+
optimized_model_dir = os.path.abspath(
422+
os.path.join(self.OUTPUT_MODEL_DIRECTORY, NEO_OPTIMIZED_MODEL_DIR))
423+
os.mkdir(optimized_model_dir)
424+
with os.scandir(self.OUTPUT_MODEL_DIRECTORY) as it:
425+
for entry in it:
426+
if os.path.abspath(entry.path) != optimized_model_dir:
427+
shutil.move(entry.path, optimized_model_dir)
428+
429+
shutil.copytree(self.INPUT_MODEL_DIRECTORY,
430+
self.OUTPUT_MODEL_DIRECTORY,
431+
dirs_exist_ok=True)
432+
self.write_properties()
433+
411434
def neo_partition(self):
412435
self.update_neuron_cache_location()
413436
self.initialize_partition_args_namespace()
@@ -447,7 +470,7 @@ def neo_partition(self):
447470
cache_manager.create_jumpstart_neuron_cache_in_cache_dir(
448471
self.jumpstart_metadata)
449472

450-
self.write_properties()
473+
self.copy_input_files_to_output()
451474

452475

453476
def main():

0 commit comments

Comments
 (0)