下载模型,并将其解压到指定目录。 Args: url (str): 模型文件的URL地址。 output_dir (str): 模型文件要保存的目录路径。 temp_tar (str, optional): 临时保存模型文件的TAR包名称,默认为'temp.tar'. Raises: Exception: 如果下载或解压过程中出现任何错误,都会抛出Exception异常。 Returns: None - 无返回值,只是在下载和解压过程中进行日志输出和清理临时文件。
(url, output_dir, temp_tar)
| 457 | |
| 458 | |
| 459 | def download_model(url, output_dir, temp_tar): |
| 460 | """ |
| 461 | 下载模型,并将其解压到指定目录。 |
| 462 | |
| 463 | Args: |
| 464 | url (str): 模型文件的URL地址。 |
| 465 | output_dir (str): 模型文件要保存的目录路径。 |
| 466 | temp_tar (str, optional): 临时保存模型文件的TAR包名称,默认为'temp.tar'. |
| 467 | |
| 468 | Raises: |
| 469 | Exception: 如果下载或解压过程中出现任何错误,都会抛出Exception异常。 |
| 470 | |
| 471 | Returns: |
| 472 | None - 无返回值,只是在下载和解压过程中进行日志输出和清理临时文件。 |
| 473 | """ |
| 474 | try: |
| 475 | temp_tar = os.path.join(output_dir, temp_tar) |
| 476 | # Download the file |
| 477 | llm_logger.info(f"\nStarting download from: {url} {temp_tar}") |
| 478 | download_file(url, temp_tar) |
| 479 | # Extract the archive |
| 480 | print("\nExtracting files...") |
| 481 | extract_tar(temp_tar, output_dir) |
| 482 | |
| 483 | except Exception: |
| 484 | # Cleanup on failure |
| 485 | if os.path.exists(temp_tar): |
| 486 | os.remove(temp_tar) |
| 487 | raise Exception( |
| 488 | f"""Failed to get model from {url}, please recheck the model name from |
| 489 | https://github.com/PaddlePaddle/PaddleNLP/blob/develop/llm/server/docs/static_models.md""" |
| 490 | ) |
| 491 | finally: |
| 492 | # Cleanup temp file |
| 493 | if os.path.exists(temp_tar): |
| 494 | os.remove(temp_tar) |
| 495 | |
| 496 | |
| 497 | class FlexibleArgumentParser(argparse.ArgumentParser): |
nothing calls this directly
no test coverage detected