Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
],
"source": [
"tokenizer = AutoTokenizer.from_pretrained(\"google-t5/t5-small\")\n",
"model = TFT5ForConditionalGeneration.from_pretrained(\"google-t5/t5-small\")\n",
"model = TFT5ForConditionalGeneration.from_pretrained(\"google-t5/t5-small\", use_safetensors=False)\n",
"\n",
"task_prefix = \"translate English to German: \"\n",
"\n",
Expand Down Expand Up @@ -581,7 +581,7 @@
" except RuntimeError as e:\n",
" print(e)\n",
"\n",
" model = TFT5ForConditionalGeneration.from_pretrained(\"google-t5/t5-small\")\n",
" model = TFT5ForConditionalGeneration.from_pretrained(\"google-t5/t5-small\", use_safetensors=False)\n",
" tokenizer = AutoTokenizer.from_pretrained(\"google-t5/t5-small\")\n",
"\n",
" def predict(inputs):\n",
Expand Down Expand Up @@ -1033,7 +1033,7 @@
" print(e)\n",
" \n",
" tokenizer = AutoTokenizer.from_pretrained(\"google-t5/t5-small\")\n",
" model = TFT5ForConditionalGeneration.from_pretrained(\"google-t5/t5-small\")\n",
" model = TFT5ForConditionalGeneration.from_pretrained(\"google-t5/t5-small\", use_safetensors=False)\n",
"\n",
" @batch\n",
" def _infer_fn(**inputs):\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
],
"source": [
"import tensorflow as tf\n",
"from transformers import pipeline\n",
"from transformers import AutoTokenizer, TFAutoModelForSequenceClassification, pipeline\n",
"\n",
"HF_DEFAULT_SENTIMENT_MODEL = \"distilbert/distilbert-base-uncased-finetuned-sst-2-english\"\n",
"\n",
"# Manually enable Huggingface tokenizer parallelism to avoid disabling with PySpark parallelism.\n",
"# See (https://github.com/huggingface/transformers/issues/5486) for more info. \n",
Expand Down Expand Up @@ -133,7 +135,12 @@
}
],
"source": [
"classifier = pipeline(\"sentiment-analysis\", device=device)"
"tokenizer = AutoTokenizer.from_pretrained(HF_DEFAULT_SENTIMENT_MODEL)\n",
"model = TFAutoModelForSequenceClassification.from_pretrained(\n",
" HF_DEFAULT_SENTIMENT_MODEL,\n",
" use_safetensors=False,\n",
")\n",
"classifier = pipeline(\"sentiment-analysis\", model=model, tokenizer=tokenizer, dtype=None)"
]
},
{
Expand Down Expand Up @@ -216,7 +223,7 @@
"source": [
"from transformers import AutoTokenizer, TFAutoModelForSequenceClassification\n",
"\n",
"model = TFAutoModelForSequenceClassification.from_pretrained(model_name)\n",
"model = TFAutoModelForSequenceClassification.from_pretrained(model_name, use_safetensors=False)\n",
"tokenizer = AutoTokenizer.from_pretrained(model_name)"
]
},
Expand All @@ -238,7 +245,7 @@
}
],
"source": [
"classifier = pipeline(\"sentiment-analysis\", model=model, tokenizer=tokenizer, device=device)\n",
"classifier = pipeline(\"sentiment-analysis\", model=model, tokenizer=tokenizer, dtype=None)\n",
"classifier(\"Nous sommes très heureux de vous présenter la bibliothèque 🤗 Transformers.\")"
]
},
Expand Down Expand Up @@ -557,7 +564,7 @@
"source": [
"def predict_batch_fn():\n",
" import tensorflow as tf\n",
" from transformers import pipeline\n",
" from transformers import AutoTokenizer, TFAutoModelForSequenceClassification, pipeline\n",
"\n",
" # Enable GPU memory growth\n",
" gpus = tf.config.experimental.list_physical_devices('GPU')\n",
Expand All @@ -569,7 +576,10 @@
" print(e)\n",
" \n",
" device = 0 if tf.config.list_physical_devices('GPU') else -1\n",
" pipe = pipeline(\"sentiment-analysis\", device=device)\n",
" model_name = \"distilbert/distilbert-base-uncased-finetuned-sst-2-english\"\n",
" tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
" model = TFAutoModelForSequenceClassification.from_pretrained(model_name, use_safetensors=False)\n",
" pipe = pipeline(\"sentiment-analysis\", model=model, tokenizer=tokenizer, dtype=None)\n",
" def predict(inputs):\n",
" return pipe(inputs.tolist())\n",
" return predict"
Expand Down Expand Up @@ -822,7 +832,7 @@
" import signal\n",
" import numpy as np\n",
" import tensorflow as tf\n",
" from transformers import pipeline\n",
" from transformers import AutoTokenizer, TFAutoModelForSequenceClassification, pipeline\n",
" from pytriton.decorators import batch\n",
" from pytriton.model_config import DynamicBatcher, ModelConfig, Tensor\n",
" from pytriton.triton import Triton, TritonConfig\n",
Expand All @@ -840,7 +850,10 @@
" \n",
" device = 0 if tf.config.list_physical_devices('GPU') else -1\n",
" \n",
" pipe = pipeline(\"sentiment-analysis\", device=device)\n",
" model_name = \"distilbert/distilbert-base-uncased-finetuned-sst-2-english\"\n",
" tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
" model = TFAutoModelForSequenceClassification.from_pretrained(model_name, use_safetensors=False)\n",
" pipe = pipeline(\"sentiment-analysis\", model=model, tokenizer=tokenizer, dtype=None)\n",
" print(f\"SERVER: Using {device} device.\")\n",
"\n",
" @batch\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2025, NVIDIA CORPORATION.
# Copyright (c) 2025-2026, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

numpy
numpy>=1.26.4,<2
pandas
matplotlib
portalocker
Expand All @@ -23,7 +23,8 @@ scikit-learn
jupyterlab
pyspark>=3.4.0
huggingface
datasets
datasets==3.*
huggingface-hub<1.0
transformers
ipywidgets
nvidia-pytriton
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,12 @@
}
],
"source": [
"train, val, test = np.split(dataframe.sample(frac=1), [int(0.8*len(dataframe)), int(0.9*len(dataframe))])"
"shuffled = dataframe.sample(frac=1)\n",
"train_end = int(0.8 * len(shuffled))\n",
"val_end = int(0.9 * len(shuffled))\n",
"train = shuffled.iloc[:train_end]\n",
"val = shuffled.iloc[train_end:val_end]\n",
"test = shuffled.iloc[val_end:]"
]
},
{
Expand Down Expand Up @@ -394,7 +399,7 @@
"def df_to_dataset(dataframe, shuffle=True, batch_size=32):\n",
" df = dataframe.copy()\n",
" labels = df.pop('target')\n",
" df = {key: value.to_numpy()[:,tf.newaxis] for key, value in dataframe.items()}\n",
" df = {key: value.to_numpy()[:,tf.newaxis] for key, value in df.items()}\n",
" ds = tf.data.Dataset.from_tensor_slices((dict(df), labels))\n",
" if shuffle:\n",
" ds = ds.shuffle(buffer_size=len(dataframe))\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"import re\n",
"import shutil\n",
"import string\n",
"import unicodedata\n",
"import matplotlib.pyplot as plt\n",
"\n",
"import tensorflow as tf\n",
Expand Down Expand Up @@ -977,6 +978,18 @@
"metadata": {},
"outputs": [],
"source": [
"def normalize_vocabulary(vocab):\n",
" normalized_vocab = []\n",
" seen = set()\n",
" for word in vocab:\n",
" word = unicodedata.normalize('NFKD', word).encode('ascii', 'ignore').decode('utf-8')\n",
" if word in (\"\", \"[UNK]\") or word in seen:\n",
" continue\n",
" seen.add(word)\n",
" normalized_vocab.append(word)\n",
" return normalized_vocab\n",
"\n",
"vectorize_layer.set_vocabulary(normalize_vocabulary(vectorize_layer.get_vocabulary()))\n",
"export_model.save('models/text_model.keras')"
]
},
Expand Down Expand Up @@ -1624,25 +1637,8 @@
"metadata": {},
"outputs": [],
"source": [
"import unicodedata\n",
"\n",
"def normalize_vocabulary(vocab):\n",
" # Normalize each word in the vocabulary to remove non-ASCII characters\n",
" normalized_vocab = [\n",
" unicodedata.normalize('NFKD', word).encode('ascii', 'ignore').decode('utf-8')\n",
" for word in vocab\n",
" ]\n",
" normalized_vocab = filter(lambda x: x != '', normalized_vocab)\n",
" normalized_vocab = list(set(normalized_vocab)) \n",
"\n",
"\n",
" return normalized_vocab\n",
"\n",
"vocab = vectorize_layer.get_vocabulary()\n",
"normalized_vocab = normalize_vocabulary(vocab)\n",
"\n",
"# Reassign the cleaned vocabulary to the TextVectorization layer\n",
"vectorize_layer.set_vocabulary(normalized_vocab)"
"# Reuse the cleaned vocabulary for the Triton model as well.\n",
"vectorize_layer.set_vocabulary(normalize_vocabulary(vectorize_layer.get_vocabulary()))"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2025, NVIDIA CORPORATION.
# Copyright (c) 2025-2026, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,10 +13,10 @@
# limitations under the License.

-r requirements.txt
torch<=2.5.1
torchvision
torch-tensorrt
torch==2.8.0
torchvision==0.23.0
torch-tensorrt==2.8.0
tensorrt --extra-index-url https://download.pytorch.org/whl/cu121
Comment thread
YanxuanLiu marked this conversation as resolved.
sentence_transformers
sentencepiece
nvidia-modelopt[all] --extra-index-url https://pypi.nvidia.com
nvidia-modelopt[all] --extra-index-url https://pypi.nvidia.com
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,8 @@
"source": [
"server_manager.start_servers(gpu_memory_utilization=0.95,\n",
" max_model_len=6600,\n",
" task=\"generate\",\n",
" enforce_eager=enforce_eager,\n",
" wait_retries=60)"
" wait_retries=180)"
]
},
{
Expand Down