4.2 Best practices and software quality
Import guarding, readiness checks, guardrails and dataset licence checks.
Key points
Import guarding lets code run with or without an optional dependency. safe_import returns the module (or a placeholder) and a boolean saying whether it loaded.
What NVIDIA says (1)
“In either of these cases, it’s important to guard the optional imports.”
A quality check confirms a service is really working before use. Triton prints a status for each model and a reason if loading failed.
What NVIDIA says (1)
“All the models should show “READY” status to indicate that they loaded correctly.”
A guardrail is a rule that checks what goes into or comes out of a model. NeMo Guardrails is an open-source Python package for this. DALI means the NVIDIA Data Loading Library. LLM means large language model.
What NVIDIA says (1)
“Use it to block, alter, or validate unsafe, off-topic, malicious, or policy-violating user inputs and model responses.”
Good practice includes checking legal and content fitness of data, not just code quality.
What NVIDIA says (1)
“It is the responsibility of each user to check the content of the dataset, review the applicable licenses, and determine if it is suitable for their intended use.”
Key terms
- NeMo Guardrails: An open-source package for programmable rules that check what goes into and out of an LLM app.
- Import guarding: Writing code so an optional package is used only when it is installed.
Sample question
Your NeMo code should use an optional package only if it is installed. Which NeMo best practice applies?
Show the answer
Answer: Guard the import with safe_import and check the returned flag
Import guarding lets code run with or without an optional dependency. safe_import returns the module (or a placeholder) and a boolean saying whether it loaded.
What NVIDIA says (1)
“In either of these cases, it’s important to guard the optional imports.”
Practice 4.2 (4 questions) Full Software Development guide
← 4.1 Working with clients on requirements · 4.3 Prompting generative models →