|  | 
| 31 | 31 | 
 | 
| 32 | 32 | PYTHON_CACHE_DIR = '/tmp/djlserving/cache' | 
| 33 | 33 | _neuronxcc_version: Optional[str] = None | 
|  | 34 | +NEO_OPTIMIZED_MODEL_DIR = 'neo_optimized_model' | 
| 34 | 35 | 
 | 
| 35 | 36 | 
 | 
| 36 | 37 | def get_neuronxcc_version() -> str: | 
| @@ -401,13 +402,35 @@ def write_properties(self) -> str: | 
| 401 | 402 |         self.properties_manager.properties = output_properties | 
| 402 | 403 |         self.properties_manager.generate_properties_file() | 
| 403 | 404 | 
 | 
|  | 405 | +        output_passthrough_properties[ | 
|  | 406 | +            "option.model_id"] = f"./{NEO_OPTIMIZED_MODEL_DIR}" | 
| 404 | 407 |         # Write out pass-through properties | 
| 405 | 408 |         properties_file = os.path.join(self.OUTPUT_MODEL_DIRECTORY, | 
| 406 | 409 |                                        'serving.properties') | 
| 407 | 410 |         with open(properties_file, "a") as f: | 
| 408 | 411 |             for k, v in output_passthrough_properties.items(): | 
| 409 | 412 |                 f.write(f"{k}={v}\n") | 
| 410 | 413 | 
 | 
|  | 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 | + | 
| 411 | 434 |     def neo_partition(self): | 
| 412 | 435 |         self.update_neuron_cache_location() | 
| 413 | 436 |         self.initialize_partition_args_namespace() | 
| @@ -447,7 +470,7 @@ def neo_partition(self): | 
| 447 | 470 |                 cache_manager.create_jumpstart_neuron_cache_in_cache_dir( | 
| 448 | 471 |                     self.jumpstart_metadata) | 
| 449 | 472 | 
 | 
| 450 |  | -        self.write_properties() | 
|  | 473 | +        self.copy_input_files_to_output() | 
| 451 | 474 | 
 | 
| 452 | 475 | 
 | 
| 453 | 476 | def main(): | 
|  | 
0 commit comments