Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tokenizer pre-download path a configurable env variable #504

Merged
merged 2 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ ARG VERSION=""
ARG VERSION_REV="0"
ARG DOWNLOAD_LLAMA_TOKENIZER=""
ARG HF_ACCESS_TOKEN=""
ARG MODEL_PREDOWNLOAD_PATH=""

# Embed the `git rev-parse HEAD` as a Docker metadata label
# Allows for linking container builds to git commits
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ services:
args:
DOWNLOAD_LLAMA_TOKENIZER: ${DOWNLOAD_LLAMA_TOKENIZER:-False}
HF_ACCESS_TOKEN: ${HF_ACCESS_TOKEN:-hfaccesstoken}
MODEL_PREDOWNLOAD_PATH: ${MODEL_PREDOWNLOAD_PATH:-/workspace/models/}
volumes:
- ${DATASET_ROOT:-./data}:/workspace/data
ports:
Expand Down Expand Up @@ -286,6 +287,7 @@ services:
- YOLOX_TABLE_STRUCTURE_INFER_PROTOCOL=grpc
- VLM_CAPTION_ENDPOINT=http://vlm:8000/v1/chat/completions
- VLM_CAPTION_MODEL_NAME=meta/llama-3.2-11b-vision-instruct
- MODEL_PREDOWNLOAD_PATH=${MODEL_PREDOWNLOAD_PATH:-/workspace/models/}
healthcheck:
test: curl --fail http://nv-ingest-ms-runtime:7670/v1/health/ready || exit 1
interval: 10s
Expand Down
4 changes: 2 additions & 2 deletions docker/scripts/post_build_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from transformers import AutoTokenizer

if os.getenv("DOWNLOAD_LLAMA_TOKENIZER") == "True":
tokenizer_path = "/workspace/models/llama-3.2-1b/tokenizer/"
tokenizer_path = os.path.join(os.environ.get("MODEL_PREDOWNLOAD_PATH"), "llama-3.2-1b/tokenizer/")
os.makedirs(tokenizer_path)

tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-1B", token=os.getenv("HF_ACCESS_TOKEN"))
tokenizer.save_pretrained(tokenizer_path)
else:
tokenizer_path = "/workspace/models/e5-large-unsupervised/tokenizer/"
tokenizer_path = os.path.join(os.environ.get("MODEL_PREDOWNLOAD_PATH"), "e5-large-unsupervised/tokenizer/")
os.makedirs(tokenizer_path)

tokenizer = AutoTokenizer.from_pretrained("intfloat/e5-large-unsupervised")
Expand Down
12 changes: 8 additions & 4 deletions src/nv_ingest/modules/transforms/text_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,19 @@ def split_and_forward(message: IngestControlMessage):
if df_filtered.empty:
return message

if os.path.exists("/workspace/models/llama-3.2-1b/tokenizer/tokenizer.json") and (
model_predownload_path = os.environ.get("MODEL_PREDOWNLOAD_PATH")

if os.path.exists(os.path.join(model_predownload_path, "llama-3.2-1b/tokenizer/tokenizer.json")) and (
tokenizer is None or tokenizer == "meta-llama/Llama-3.2-1B"
):
tokenizer = "/workspace/models/llama-3.2-1b/tokenizer/"
elif os.path.exists("/workspace/models/e5-unsupervised-large/tokenizer/tokenizer.json") and (
tokenizer is None or tokenizer == "intfloat/e5-large-unsupervised"
):
elif os.path.exists(
os.path.join(model_predownload_path, "e5-unsupervised-large/tokenizer/tokenizer.json")
) and (tokenizer is None or tokenizer == "intfloat/e5-large-unsupervised"):
tokenizer = "/workspace/models/e5-unsupervised-large/tokenizer/"

logger.info(tokenizer)

tokenizer_model = AutoTokenizer.from_pretrained(tokenizer, token=hf_access_token)

split_docs = []
Expand Down
Loading