Skip to content

Commit 2d498bf

Browse files
memadi-nvnina-xu
andauthored
fix: update nim api key (#262)
<!-- SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. --> <!-- SPDX-License-Identifier: Apache-2.0 --> <!-- Thank you for contributing to Safe Synthesizer! --> # Summary <!-- Brief description of changes --> - Standardizing `NIM_API_KEY` to `NSS_INFERENCE_KEY` and `NIM_ENDPOINT_URL` with `NSS_INFERENCE_ENDPOINT ` in NSS to match what it's called on the basic build docs. - Set `NSS_INFERENCE_ENDPOINT = https://integrate.api.nvidia.com/v1` as the default. - Update the docs to clarify that `NSS_INFERENCE_KEY` and optional `NSS_INFERENCE_ENDPOINT` need to be set when using CLI and SDK. - Address feedbacks from the notebook: - Remove addition of the inference end point since a default is set. - Remove "next steps" section. - Remove `with_replace_pii`, and only add a comment about how it disables PII replacement. ## Pre-Review Checklist <!-- These checks should be completed before a PR is reviewed, --> <!-- but you can submit a draft early to indicate that the issue is being worked on. --> Ensure that the following pass: - [x] `make format && make check` or via prek validation. - [x] `make test` passes locally - [ ] `make test-e2e` passes locally - [ ] `make test-ci-container` passes locally (recommended) - [ ] GPU CI status check passes -- comment `/sync` on this PR to trigger a run (auto-triggers on ready-for-review) ## Pre-Merge Checklist <!-- These checks need to be completed before a PR is merged, --> <!-- but as PRs often change significantly during review, --> <!-- it's OK for them to be incomplete when review is first requested. --> - [ ] New or updated tests for any fix or new behavior - [ ] Updated documentation for new features and behaviors, including docstrings for API docs. ## Other Notes <!-- Please add the issue number that should be closed when this PR is merged. --> - Closes #<issue> --------- Signed-off-by: memadi <memadi@nvidia.com> Signed-off-by: Marjan Emadi <memadi@nvidia.com> Co-authored-by: Nina Xu <19981858+nina-xu@users.noreply.github.com>
1 parent 8e665ca commit 2d498bf

15 files changed

Lines changed: 375 additions & 357 deletions

File tree

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,19 @@ Common values: `FLASHINFER`, `FLASH_ATTN`, `TORCH_SDPA`, `TRITON_ATTN`, `FLEX_AT
235235
## NIM Integration
236236
237237
Column classification uses a NIM/OpenAI-compatible endpoint to detect entity types
238-
in your data. The endpoint is configured via `NIM_ENDPOINT_URL`; if it is unset,
239-
classification is skipped and the pipeline falls back to default entity detection,
240-
logging an error and falling back rather than raising it to the user.
238+
in your data. `NSS_INFERENCE_ENDPOINT` defaults to `https://integrate.api.nvidia.com/v1`;
239+
override it to use a different endpoint.
240+
241+
When using the CLI or Python SDK, set `NSS_INFERENCE_KEY` (and `NSS_INFERENCE_ENDPOINT` only if not
242+
using the default) so column classification can run.
241243
242244
### Local Endpoint
243245
244246
To point to a locally hosted LLM:
245247
246248
```bash
247-
export NIM_ENDPOINT_URL="https://your-local-nim-endpoint"
248-
export NIM_API_KEY="your-api-key" # pragma: allowlist secret
249+
export NSS_INFERENCE_ENDPOINT="https://your-local-nim-endpoint"
250+
export NSS_INFERENCE_KEY="your-api-key" # pragma: allowlist secret
249251
```
250252
251253
### Disable Classification

containers/Dockerfile.cuda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# -v HOST:CONTAINER bind-mount data and HF cache (use absolute paths)
2727
# -e HF_HOME=... persist model downloads across container runs
2828
# -e HF_TOKEN=... HF token for gated models (Llama, Mistral, etc.)
29-
# -e NIM_API_KEY=... NIM endpoint key for PII classification (optional)
29+
# -e NSS_INFERENCE_KEY=... inference API key for PII column classification (optional)
3030
#
3131
# Interactive shell:
3232
# docker run -it --gpus all --shm-size=1g \

containers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Key flags:
7272
- `-v HOST:CONTAINER` -- bind-mount data and HF cache; Docker requires absolute paths (use `$(pwd)` to expand relative ones)
7373
- `-e HF_HOME=...` -- persist model downloads across container runs
7474
- `-e HF_TOKEN=...` -- Hugging Face token for gated models (Llama, Mistral, etc.)
75-
- `-e NIM_API_KEY=...` -- NIM endpoint key for PII classification (optional, only when `NIM_ENDPOINT_URL` is set)
75+
- `-e NSS_INFERENCE_KEY=...` -- inference API key for PII column classification (optional; `NSS_INFERENCE_ENDPOINT` defaults to the NVIDIA integrate URL if unset)
7676
- `-e WANDB_API_KEY=...` -- WandB API key for experiment tracking (optional)
7777
- `--user "$(id -u):$(id -g)"` -- match host uid if you get "Permission denied" writing artifacts
7878

docs/tutorials/safe-synthesizer-101.ipynb

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@
5959
"metadata": {},
6060
"source": [
6161
"\n",
62-
"### 🔑 Set the NIM API key and configure column classification\n",
62+
"### 🔑 Set the inference API key for column classification\n",
6363
"\n",
64-
"Setting `NIM_API_KEY` is optional but strongly recommended.\n",
65-
"\n",
66-
"NeMo Safe Synthesizer uses an LLM‑based column classifier to automatically infer column types and improve PII detection accuracy. To enable this feature, you must set both `NIM_ENDPOINT_URL` and `NIM_API_KEY`. You can obtain an API key from [build.nvidia.com](https://build.nvidia.com/settings/api-keys)\n"
64+
"NeMo Safe Synthesizer uses an LLM‑based column classifier to automatically infer column types and improve PII detection accuracy. To enable this feature, set `NSS_INFERENCE_KEY` (the inference endpoint defaults to the NVIDIA integrate URL. You can obtain an API key from [build.nvidia.com](https://build.nvidia.com/settings/api-keys)). Setting this value is optional but strongly recommended.\n"
6765
]
6866
},
6967
{
@@ -76,18 +74,14 @@
7674
"import os\n",
7775
"import getpass\n",
7876
"\n",
79-
"# Set the NIM endpoint URL\n",
80-
"os.environ[\"NIM_ENDPOINT_URL\"] = \"https://integrate.api.nvidia.com/v1\"\n",
81-
"print(\"NIM_ENDPOINT_URL is set.\")\n",
82-
"\n",
83-
"# Setting NIM_API_KEY is optional but strongly recommended for PII replacement.\n",
84-
"if \"NIM_API_KEY\" not in os.environ:\n",
85-
" os.environ[\"NIM_API_KEY\"] = getpass.getpass(\"Paste NIM API key (or press Enter to skip): \")\n",
86-
"if os.environ.get(\"NIM_API_KEY\"):\n",
87-
" print(\"NIM_API_KEY is set\")\n",
77+
"# Setting NSS_INFERENCE_KEY is optional but strongly recommended for PII replacement.\n",
78+
"if \"NSS_INFERENCE_KEY\" not in os.environ:\n",
79+
" os.environ[\"NSS_INFERENCE_KEY\"] = getpass.getpass(\"Paste inference API key (or press Enter to skip): \")\n",
80+
"if os.environ.get(\"NSS_INFERENCE_KEY\"):\n",
81+
" print(\"NSS_INFERENCE_KEY is set\")\n",
8882
"else:\n",
8983
" print(\n",
90-
" \"NIM_API_KEY is not set. \"\n",
84+
" \"NSS_INFERENCE_KEY is not set. \"\n",
9185
" \"We strongly recommend setting a key.\"\n",
9286
" )"
9387
]
@@ -144,7 +138,9 @@
144138
"source": [
145139
"from nemo_safe_synthesizer.sdk.library_builder import SafeSynthesizer\n",
146140
"\n",
147-
"builder = SafeSynthesizer().with_data_source(df).with_replace_pii()\n",
141+
"\n",
142+
"# To disable PII replacement for the run, chain `.with_replace_pii(enable=False)` on the builder before `run()`.\n",
143+
"builder = SafeSynthesizer().with_data_source(df)\n",
148144
"\n",
149145
"builder.run()\n",
150146
"results = builder.results"
@@ -209,30 +205,6 @@
209205
" f.write(results.evaluation_report_html)\n",
210206
" print(f\"The HTML evaluation report is saved in {report_path}.\")"
211207
]
212-
},
213-
{
214-
"cell_type": "markdown",
215-
"id": "e9a19fcc",
216-
"metadata": {},
217-
"source": [
218-
"### ➡️ Next Steps\n",
219-
"\n",
220-
"Now that you've completed your first Safe Synthesizer job, explore more advanced features:\n",
221-
"\n",
222-
"### Advanced Tutorials\n",
223-
"\n",
224-
"- [Differential Privacy Tutorial](https://aire.gitlab-master-pages.nvidia.com/microservices/nmp/latest/nemo-microservices/latest/safe-synthesizer/tutorials/differential-privacy.html) - Apply mathematical privacy guarantees\n",
225-
"\n",
226-
"- [PII Replacement Tutorial](https://aire.gitlab-master-pages.nvidia.com/microservices/nmp/latest/nemo-microservices/latest/safe-synthesizer/tutorials/pii-replacement.html) - Advanced PII detection and replacement\n",
227-
"\n",
228-
"\n",
229-
"### Try These Next\n",
230-
"\n",
231-
"1. **Customize PII replacement**: Configure specific entity types and replacement strategies\n",
232-
"2. **Enable differential privacy**: Add formal privacy guarantees with epsilon and delta parameters\n",
233-
"3. **Tune generation parameters**: Experiment with temperature and sampling to understand how they impact quality and privacy scores. More on generation parameters [here](https://github.com/NVIDIA-NeMo/Safe-Synthesizer/blob/main/docs/user-guide/configuration.md#generation)\n",
234-
"4. **Use your own data**: Replace the sample dataset with your sensitive data\n"
235-
]
236208
}
237209
],
238210
"metadata": {

docs/user-guide/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Key config parameters:
149149

150150
| Field | Default | Description | Guidance |
151151
|-------|---------|-------------|----------|
152-
| `replace_pii.globals.classify.enable_classify` | `true` | Enable LLM-based column classification | Requires `NIM_ENDPOINT_URL`; set to `false` if no LLM endpoint is available |
152+
| `replace_pii.globals.classify.enable_classify` | `true` | Enable LLM-based PII column classification | When using the CLI, set `NSS_INFERENCE_KEY` (and optionally `NSS_INFERENCE_ENDPOINT`); set to `false` if no LLM endpoint is available |
153153
| `replace_pii.globals.classify.entities` | (see default list) | Entity types used for LLM-based column classification. Defaults to 15 types covering names, addresses, phone numbers, emails, SSN, national/tax IDs, and credit/debit cards -- see [PII Replacement](../product-overview/pii_replacement.md) and [`PiiReplacerConfig`][nemo_safe_synthesizer.config.replace_pii.PiiReplacerConfig] | Override to add or remove entity types from classification |
154154
| `replace_pii.globals.ner.ner_threshold` | `0.3` | GLiNER confidence threshold for NER detection | Lower to catch more entities (more false positives); raise to reduce false positives |
155155

docs/user-guide/docker.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ docker run --gpus all --shm-size=1g \
123123
| Variable | Required | Purpose |
124124
|----------|----------|---------|
125125
| `HF_TOKEN` | For gated models | Hugging Face token for downloading gated models (Llama, Mistral, etc.). Get one at [hf.co/settings/tokens](https://huggingface.co/settings/tokens) |
126-
| `NIM_API_KEY` | For PII classification | API key for the NIM endpoint used by PII column classification. Only needed when `NIM_ENDPOINT_URL` is set |
127-
| `NIM_ENDPOINT_URL` | For PII classification | NIM/OpenAI-compatible endpoint URL for PII column classification |
126+
| `NSS_INFERENCE_KEY` | For PII classification | API key for `NSS_INFERENCE_ENDPOINT`. Set when using the CLI/SDK for column classification |
127+
| `NSS_INFERENCE_ENDPOINT` | For PII classification | NIM/OpenAI-compatible endpoint URL (default: `https://integrate.api.nvidia.com/v1`). Override for a custom endpoint |
128128
| `WANDB_API_KEY` | For experiment tracking | WandB API key. Only needed when `--wandb-mode online` is used |
129129

130130
If `HF_TOKEN` is already stored in your HF cache (`~/.cache/huggingface/token`),

docs/user-guide/environment.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ are cached, and which network endpoints are used.
2727
| `NSS_DATASET_REGISTRY` | `--dataset-registry` | Dataset registry YAML path/URL |
2828
| `NSS_WANDB_MODE` | `--wandb-mode` | WandB mode (alias for `WANDB_MODE`) |
2929
| `NSS_WANDB_PROJECT` | `--wandb-project` | WandB project name (alias for `WANDB_PROJECT`) |
30-
| `NIM_ENDPOINT_URL` | -- | LLM endpoint for PII column classification |
31-
| `NIM_API_KEY` | -- | API key (optional -- only for direct endpoints) |
30+
| `NSS_INFERENCE_ENDPOINT` | -- | LLM endpoint for PII column classification (default: `https://integrate.api.nvidia.com/v1`) |
31+
| `NSS_INFERENCE_KEY` | -- | API key for the `NSS_INFERENCE_ENDPOINT` is required for column classification in both CLI and SDK. |
3232
| `NIM_MODEL_ID` | -- | Column classification model ID |
3333
| `LOCAL_FILES_ONLY` | -- | Set to `true` for offline mode (Unsloth, GLiNER) |
3434
| `SAFE_SYNTHESIZER_CPU_COUNT` | -- | NER CPU processes |
@@ -162,17 +162,19 @@ Common values: `FLASHINFER`, `FLASH_ATTN`, `TORCH_SDPA`, `TRITON_ATTN`,
162162

163163
NIM endpoint, API keys, and CPU parallelism for PII detection.
164164

165-
### `NIM_ENDPOINT_URL`
165+
### `NSS_INFERENCE_ENDPOINT`
166166

167-
The NIM/OpenAI-compatible endpoint used for PII column classification. When
168-
unset, an error is logged and the pipeline falls back to NER-only detection.
169-
Set this to enable LLM-based column classification:
167+
The NIM/OpenAI-compatible endpoint used for PII column classification. Defaults
168+
to `https://integrate.api.nvidia.com/v1` when unset. Override for a custom endpoint:
170169

171170
```bash
172-
export NIM_ENDPOINT_URL="https://your-local-nim-endpoint"
173-
export NIM_API_KEY="your-api-key" # pragma: allowlist secret
171+
export NSS_INFERENCE_ENDPOINT="https://your-llm-inference-endpoint"
172+
export NSS_INFERENCE_KEY="your-api-key" # pragma: allowlist secret
174173
```
175174

175+
When using the CLI or SDK: for column classification to work, set `NSS_INFERENCE_KEY` (and
176+
`NSS_INFERENCE_ENDPOINT` only if you are not using the default URL).
177+
176178
To disable column classification entirely instead of pointing it at a local
177179
endpoint, use the `replace_pii.globals.classify.enable_classify` config option.
178180
PII classify config is deeply nested -- use YAML or SDK:
@@ -201,10 +203,10 @@ PII classify config is deeply nested -- use YAML or SDK:
201203
)
202204
```
203205

204-
### `NIM_API_KEY`
206+
### `NSS_INFERENCE_KEY`
205207

206-
API key for the NIM endpoint. Required when `NIM_ENDPOINT_URL` points to an
207-
authenticated endpoint.
208+
API key for the NSS inference endpoint. Required for PII column classification when using the
209+
CLI and SDK (with the default or custom `NSS_INFERENCE_ENDPOINT`).
208210

209211
### `NIM_MODEL_ID`
210212

docs/user-guide/evaluating-data.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,10 @@ or
8989
Could not perform classify, falling back to default entities.
9090
```
9191

92-
Fix: set entity types explicitly in your config, or check that `NIM_ENDPOINT_URL`
93-
is reachable. PII classify config is deeply nested -- use YAML or SDK:
92+
When `NSS_INFERENCE_KEY` is not set, the same log line is followed by guidance to set it (and a note that `NSS_INFERENCE_ENDPOINT` is optional with the default API). When the key is set, a traceback may be included to show the underlying API error.
93+
94+
Fix: set entity types explicitly in your config, or when using the CLI ensure
95+
`NSS_INFERENCE_KEY` is set (and `NSS_INFERENCE_ENDPOINT` if not using the default). PII classify config is deeply nested -- use YAML or SDK:
9496

9597
=== "Config reference"
9698

docs/user-guide/running.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -441,20 +441,22 @@ default in both the CLI and SDK. PII on by default means no config flag is neede
441441

442442
### LLM Column Classification
443443

444-
To enable LLM-based PII column classification (optional), set the endpoint
445-
before running the pipeline. Any OpenAI-compatible inference endpoint
446-
works -- not just NVIDIA NIM:
444+
To enable LLM-based PII column classification (optional), set the API key
445+
before running the pipeline. The endpoint defaults to
446+
`https://integrate.api.nvidia.com/v1`; override `NSS_INFERENCE_ENDPOINT` for a
447+
custom OpenAI-compatible endpoint.
447448

448-
```bash
449-
export NIM_ENDPOINT_URL="https://integrate.api.nvidia.com/v1" # or your own OpenAI-compatible endpoint
449+
When using the CLI, set both for column classification:
450450

451-
export NIM_API_KEY="your-api-key" # pragma: allowlist secret (optional -- only needed for direct endpoints, not inference gateways)
451+
```bash
452+
export NSS_INFERENCE_ENDPOINT="https://integrate.api.nvidia.com/v1" # optional; this is the default
453+
export NSS_INFERENCE_KEY="your-api-key" # pragma: allowlist secret (required for column classification with the inference endpoint)
452454
```
453455

454-
When `NIM_ENDPOINT_URL` is unset, the classification step is attempted but
456+
PII column classification requires `NSS_INFERENCE_KEY` (and optionally `NSS_INFERENCE_ENDPOINT` if not using the default).
457+
When `NSS_INFERENCE_KEY` is unset, the classification step is attempted but
455458
falls back to NER-only detection (with an error log). No environment
456-
variables are required for NER-only PII replacement; column classification
457-
requires `NIM_ENDPOINT_URL`.
459+
variables are required for NER-only PII replacement.
458460

459461
See [Configuration Reference -- Replacing PII](configuration.md#replacing-pii) for the full parameter reference.
460462

0 commit comments

Comments
 (0)