Skip to content

fix: make TDgpt Docker model startup and downloads robust#35353

Closed
tomchon wants to merge 5 commits into
mainfrom
fix-tdgpt-entrypoint-args
Closed

fix: make TDgpt Docker model startup and downloads robust#35353
tomchon wants to merge 5 commits into
mainfrom
fix-tdgpt-entrypoint-args

Conversation

@tomchon
Copy link
Copy Markdown
Contributor

@tomchon tomchon commented May 20, 2026

Summary

  • Launch TDgpt non-tdtsfm model servers with argparse flags from Docker entrypoint.
  • Add shared Hugging Face download helper with correct boolean parsing, endpoint override support, and fallback from non-official endpoints to official Hugging Face.
  • Wire Docker downloader and non-tdtsfm model service scripts to the helper, with focused tests for endpoint/fallback behavior.

Test Plan

  • python3 -m pytest tools/tdgpt/tests/hf_download_test.py tools/tdgpt/tests/model_downloader_test.py -q
  • python3 -m py_compile tools/tdgpt/taosanalytics/misc/hf_download.py tools/tdgpt/taosanalytics/misc/model_downloader.py tools/tdgpt/taosanalytics/tsfmservice/chronos-server.py tools/tdgpt/taosanalytics/tsfmservice/timemoe-server.py tools/tdgpt/taosanalytics/tsfmservice/timesfm-server.py tools/tdgpt/taosanalytics/tsfmservice/moirai-server.py tools/tdgpt/taosanalytics/tsfmservice/moment-server.py
  • git diff --check
  • In-image validation on 192.168.3.91 with tdengine/tdgpt-arm64:3.4.1.9 for False parsing and endpoint fallback call sequence

chenhaoran and others added 5 commits May 18, 2026 01:04
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 20, 2026 13:03
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a centralized Hugging Face download utility (hf_download.py) that implements fallback logic and environment variable configuration, replacing direct snapshot_download calls across multiple model server scripts. Additionally, it refines argument handling in the Docker entrypoint and the model downloader tool, while introducing new unit tests. Review feedback recommends adopting argparse for more robust command-line argument parsing and utilizing os.path.join for cross-platform path construction in test scripts.

Comment on lines 37 to +48
if len(sys.argv) < 4:
print("invalid parameters, e.g.,:\n python model_downloader.py model_directory model_name ep_enable")
exit(-1)
sys.exit(1)

path = sys.argv[1].strip('\'"')
model_name = sys.argv[2].strip('\'"')
ep_enable = bool(sys.argv[3])
ep_raw = sys.argv[3]
try:
ep_enable = parse_bool(ep_raw)
except ValueError:
print(f"invalid ep_enable parameter: {ep_raw}")
sys.exit(1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The argument parsing here is done manually using sys.argv. While functional, this is less robust and user-friendly than using the argparse module. The other server scripts in this PR have been updated to use argparse. For consistency and better maintainability (e.g., automatic help messages, better error handling), consider refactoring this part to use argparse as well.

import pytest


sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/..")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better portability and to adhere to best practices, it's recommended to use os.path.join for constructing paths instead of string concatenation. This will ensure the code works correctly on different operating systems.

Suggested change
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + "/..")
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))

import pytest


tdgpt_root = os.path.dirname(os.path.abspath(__file__)) + "/.."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For better portability and to adhere to best practices, it's recommended to use os.path.join for constructing paths instead of string concatenation. This will ensure the code works correctly on different operating systems.

Suggested change
tdgpt_root = os.path.dirname(os.path.abspath(__file__)) + "/.."
tdgpt_root = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves TDgpt Docker startup and Hugging Face model download robustness by centralizing endpoint/boolean handling and updating model servers + downloader to use the shared helper.

Changes:

  • Add hf_download.py helper with robust boolean parsing, endpoint resolution, and fallback from custom/mirror endpoints to official Hugging Face.
  • Update TDgpt model downloader and non-tdtsfm model servers to use the shared download helper.
  • Add focused unit tests for boolean parsing, endpoint precedence, and fallback behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tools/tdgpt/taosanalytics/misc/hf_download.py New shared helper for endpoint resolution and snapshot download fallback.
tools/tdgpt/taosanalytics/misc/model_downloader.py Uses helper; fixes CLI boolean parsing and exits with consistent error code.
tools/tdgpt/taosanalytics/tsfmservice/chronos-server.py Switches to helper for model downloads; adds misc path for import.
tools/tdgpt/taosanalytics/tsfmservice/moirai-server.py Switches to helper for model downloads; adds misc path for import.
tools/tdgpt/taosanalytics/tsfmservice/moment-server.py Switches to helper for model downloads; adds misc path for import.
tools/tdgpt/taosanalytics/tsfmservice/timemoe-server.py Switches to helper for model downloads; adds misc path for import.
tools/tdgpt/taosanalytics/tsfmservice/timesfm-server.py Switches to helper for model downloads; adds misc path for import.
tools/tdgpt/tests/hf_download_test.py New tests covering parse/endpoint precedence/fallback behaviors.
tools/tdgpt/tests/model_downloader_test.py New test verifying invalid boolean input exits with code 1.
packaging/docker/entrypoint.sh Passes argparse flags to non-tdtsfm servers instead of positional args.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +79 to +82
model_args=(--model-folder "${subdir}" --model-name "${model_name}")
if [ "${ENDPOINT_ENABLE}" == "True" ]; then
model_args+=(--enable-ep)
fi
**kwargs: Any,
) -> str:
endpoint = resolve_endpoint(enable_ep)
print(f"set the download ep:{endpoint}")
@tomchon
Copy link
Copy Markdown
Contributor Author

tomchon commented May 21, 2026

Superseded by the clean download-only PR: #35355

@tomchon tomchon closed this May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants