Doc writing guide#
Guide to Writing Model Tutorial Doc#
docs/source/_templates/Model-Deployment-Tutorial-Template.md is a template for writing model deployment tutorials. You can copy and modify it to create new docs.
Testable doc code block generation (model-code)#
For documentation authors: how to insert testable command blocks into docs
For developers: how to add a new converter
Built-in supported converter_tag values:
converter_tag |
Renders |
YAML source |
|---|---|---|
|
A single node's env exports + |
|
|
One host's env exports + |
|
|
One external-DP node's env exports + |
|
|
One |
|
|
The load-balance proxy launch command |
|
Local debugging and generation#
Generate only (without building the full site)#
# Generate all model-code artifacts under docs/source/tutorials/models/
python3 tools/docs_codegen/cli.py
# Generate artifacts for a single document
python3 tools/docs_codegen/cli.py --doc docs/source/tutorials/models/Kimi-K2-Thinking.md
# Generate a single block and print it (no files written)
python3 tools/docs_codegen/cli.py \
--block docs/source/tutorials/models/Kimi-K2-Thinking.md::kimi_k2_thinking_single_node \
--dry-run --stdout
By default, artifacts are written to: docs/_build/doc_codegen/<doc_stem>/<block_name>.sh.
备注
After the script is generated, please make sure to check whether the generated content is runnable, especially key parts such as environment variables and command-line parameters.
Build the site & preview locally#
# Install documentation build dependencies
python3 -m pip install -r docs/requirements-docs.txt
# (Optional) Clean previous builds
make -C docs clean
# Build the English site
make -C docs html
# (Optional) Build the Chinese site
make -C docs intl
# Preview locally
python3 -m http.server -d docs/_build/html 8000
# Then open in a browser:
# http://localhost:8000
For developers: add a new converter#
A converter turns one loaded YAML file plus one parsed ModelCodeBlock into a
GeneratedScript. The current pipeline is:
BlockScannerparsesmodel-codefences and accepts only options listed inMODEL_CODE_OPTION_NAMES.YamlLoaderloadstest_case_path.get_converter()looks upblock.converter_tagfrombuild_default_converters().The selected converter returns
GeneratedScript(content=..., language="shell").GeneratorServicereplaces{{ generated }}in the block body, validates that the final script is non-empty, and writesdocs/_build/doc_codegen/<doc_stem>/<block_name>.sh.
To add a converter:
In
tools/docs_codegen/converters.py, add aBaseConvertersubclass with a uniquename. That name is the value authors put in:converter_tag:.Implement
convert(self, loaded_yaml, *, block) -> GeneratedScript. Usemake_docs_codegen_error(..., block=block)for user-facing validation errors so the CLI and Sphinx output include document context.Reuse helpers from
tools/docs_codegen/utils.py, such asrequire_mapping,require_mapping_list,require_scalar_mapping,require_indexed_mapping,require_node_field,parse_command_tokens,substitute_template_positionals, andrender_cli_command.Register the converter in
build_default_converters(). If it is not registered,get_converter()will reject the newconverter_tag.If the converter needs new directive metadata, add the option name to
MODEL_CODE_OPTION_NAMESintools/docs_codegen/scanner.pyand toModelCodeDirective.option_specintools/docs_codegen/sphinx_extension.py. Read the option withblock.get_option("<option_name>").Add or update tests in
tests/ut/tools/test_docs_codegen.py. Cover the successful render path, required option validation, YAML shape validation, and any CLI/Sphinx scanner behavior affected by new metadata.Add a real
model-codeexample in a model tutorial, preferably underdocs/source/tutorials/models/, and point it to an existing YAML file undertests/.Validate with the CLI:
python3 tools/docs_codegen/cli.py --doc <your_doc> --dry-run python3 tools/docs_codegen/cli.py --block <your_doc>::<block_name> --dry-run --stdout
If a converter should render something other than shell, set
GeneratedScript.language accordingly so Sphinx can highlight the generated
literal block correctly.