sampling
Operate BigGAN-PyTorch sampling from compatible checkpoints, including EMA and batch-normalization statistics, image sheets, NPZ export, truncation curves, and repository-specific Inception evaluation.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- sampling
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Operate BigGAN-PyTorch sampling from compatible checkpoints, including EMA and batch-normalization statistics, image sheets, NPZ export, truncation curves, and repository-specific Inception evaluation.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/api-reference.md9.3 KB
- 参考文档references/troubleshooting.md10.6 KB
- 参考文档references/workflows.md11.4 KB
03 SKILL.md 正文
BigGAN-PyTorch sampling
Use this skill when the task is to load a trained BigGAN-PyTorch generator,
produce random or conditional/interpolated images, export a TensorFlow-compatible
NPZ, or compare the repository's PyTorch Inception metrics. Work from the
repository root so that sample.py, utils.py, inception_utils.py, and the
model module can be imported.
This is a CUDA sampling path: sample.py constructs G with .cuda(), uses
CUDA distributions for z and y, and the metric wrapper also moves Inception
to CUDA. Confirm the CUDA, PyTorch, torchvision, and checkpoint environment
before launching a large run. Read all three bundled references for exact flag
semantics and recovery procedures.
Operating procedure
- Resolve the checkpoint before choosing outputs. Identify the exact
weights_root/<experiment_name>/directory and the suffix to load. An empty suffix meansG.pthandstate_dict.pth;best0andcopy0meanG_best0.pth/state_dict_best0.pthandG_copy0.pth/state_dict_copy0.pth, respectively. A usable normal-G run needs the generator and state dict; a--use_emarun additionally needsG_ema[_suffix].pth.--load_weightsselects a file suffix, not a directory. - Make the architecture agree with the saved config. Prefer an explicit
--experiment_name NAME --load_weights SUFFIX --config_from_namewhen the checkpoint has a saved state dict. The bootstrap state-dict load happens beforeupdate_config_roots, so if the checkpoint is outside the defaultweights/, pass its actual--weights_rootexplicitly as well as--base_rootif desired. Without--config_from_name, supply the training architecture flags yourself;strict=Falseinsample.pyis not a remedy for incompatible tensor shapes. - Select normal or EMA parameters deliberately. Omit
--use_emato loadG[_suffix].pth. Use--use_emaonly when the checkpoint was saved with an EMA generator and the matchingG_ema[_suffix].pthexists.--emadescribes the training/configuration and contributes to auto-generated experiment names;--use_emacontrols which generator state is loaded for evaluation. - Fix the normalization/statistics mode before comparing samples.
--G_eval_modecallsG.eval()and uses running BatchNorm estimates. With the custommyBNimplementation,--accumulate_statsruns--num_standing_accumulationsrandom forward passes in training mode and then switches to eval. KeepG_eval_mode,mybn, accumulation count, EMA choice, andz_varfixed for fair comparisons. The BigGAN recipe uses--mybn --accumulate_stats --num_standing_accumulations 32when standing statistics are wanted; the provided main sampling recipe instead uses--use_ema --G_eval_mode. - Set noise and batch size explicitly.
--z_varcontrols thevarfield of the custom normalDistribution. In this code that field is passed as the second argument toTensor.normal_, i.e. as the normal scale despite the historical “variance” name.G_batch_sizeis set tomax(--G_batch_size, --batch_size), so lower both flags when reducing GPU memory.--seedseeds PyTorch CUDA and NumPy RNGs but does not make every multi-GPU or cuDNN operation deterministic. - Choose one or more output actions and check their prerequisites.
--sample_randomwrites a normalizedrandom_samples.jpg;--sample_sheetswrites class-conditional sheets;--sample_interpswrites Z/Y interpolation sheets;--sample_npz --sample_num_npz Nwritessamples.npzwithxuint8 CHW images andyinteger labels; and metric flags compute repository-specific scores. Create the samples root first: the script does not callutils.prepare_root, and NPZ/random output assumes the experiment directory already exists. Seereferences/workflows.mdfor exact layout and commands. - Treat metric names as implementation-specific. The built-in path uses
torchvision Inception, ImageNet normalization, 299x299 resizing, and
<base-dataset>_inception_moments.npz. Its IS/FID are explicitly unofficial and not numerically interchangeable with the legacy TensorFlow metric. To obtain the TensorFlow-style IS, first produce the NPZ and then run the repository's TensorFlow 1.3-or-earlier evaluator. Record the implementation, weights (normal/EMA), mode,z_var, image count, and moments used with every score.
Standard command shape
For a checkpoint with a saved config, use a command of this form (replace the paths and name; do not invent a name from a changed sampling batch size):
mkdir -p /path/to/samples /path/to/samples/EXPERIMENT
python sample.py \
--experiment_name EXPERIMENT --weights_root /path/to/weights \
--load_weights best0 --config_from_name \
--batch_size 32 --G_batch_size 32 --seed 0 \
--use_ema --G_eval_mode --sample_random
Add only the required output flags. A truncation sweep, for example, adds
--sample_inception_metrics --sample_trunc_curves 0.05_0.05_1.0; this is a
metric run, not a cheap image smoke test. Do not start with 50,000 images or
multiple sheets when first validating a checkpoint.
Required recovery behavior
- For missing weights, inspect the experiment directory and repair the
--weights_root,--experiment_name, or--load_weightsselection. A missingstate_dict[_suffix].pthprevents--config_from_name; recover the saved config or provide every architecture argument explicitly. - For an EMA load failure, remove
--use_emaonly if a normal-G evaluation is acceptable; otherwise locate a checkpoint containing the matchingG_ema[_suffix].pth. Never label a normal-G result as an EMA result. - For missing Inception moments, generate the dataset moments using the data
preparation/moments script, put the file where
inception_utils.pywill search, or restrict the run to checkpoint/image loading after applying the lazy-metrics source fix described inreferences/troubleshooting.md.--no_fidis not a missing-moments workaround because moments are loaded before the metric flags are consulted. - For incompatible configs, load the state dict's saved config, use
--config_from_name, and keep only documented runtime overrides. A shape mismatch means the checkpoint and model are genuinely incompatible; do not paper over it withstrict=False. - For CUDA OOM, reduce both
--batch_sizeand--G_batch_size, disable--parallelonly if it reduces overhead on the available topology, and reduce image counts or run outputs separately. NPZ sampling accumulates all generated arrays in host memory before writing, so large--sample_num_npzvalues can also exhaust RAM. - For
sample.py --helpcrashing withValueError: unsupported format character '#', the--logstylehelp text inutils.pycontains literal%#.#f/%#.#estrings. Escape the percent signs as%%#.#fand%%#.#e(or remove the formatting examples), then retry help. Until that source-only fix is made, use known flags directly rather than treating the help crash as a checkpoint failure.
For the complete flag contract, file names, metric caveats, multi-GPU behavior,
and failure matrix, read references/api-reference.md,
references/workflows.md, and references/troubleshooting.md.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).