tfhub-conversion
Converts legacy DeepMind TFHub BigGAN generator modules at 128, 256, or 512 resolution into BigGAN-PyTorch state dictionaries and optionally generates CUDA sample images through the repository's reference converter.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- tfhub-conversion
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Converts legacy DeepMind TFHub BigGAN generator modules at 128, 256, or 512 resolution into BigGAN-PyTorch state dictionaries and optionally generates CUDA sample images through the repository's reference converter.
- disable-model-invocation
- true
02 资源文件 3
- 参考文档references/api-reference.md9.4 KB
- 参考文档references/troubleshooting.md8.7 KB
- 参考文档references/workflows.md9.0 KB
03 SKILL.md 正文
TFHub conversion
Use this route only for the repository's legacy TFHub/converter.py workflow:
porting a DeepMind BigGAN generator downloaded from TensorFlow Hub into a
PyTorch .pth state dictionary. The supported resolutions are 128, 256, and
512. This is not a general TensorFlow-to-PyTorch conversion tool and it does
not convert a discriminator or a complete training checkpoint.
Reference-only status. This workflow is reference-only unless an isolated environment with legacy TensorFlow 1.x-compatible APIs, TensorFlow Hub, the required Python packages, network access (or a suitable existing HDF5 intermediate), and a compatible CUDA GPU for sampling is deliberately available. It was not runtime verified. In particular, do not report a successful conversion merely because the Python files parse or because
load_state_dict(..., strict=False)returns.
Read before acting
- Read
references/workflows.mdfor the end-to-end command sequence, working directory requirement, download/cache behavior, outputs, and sample checks. - Read
references/api-reference.mdfor the converter functions, resolution table, TensorFlow-to-PyTorch mappings, and every command-line flag. - Read
references/troubleshooting.mdbefore changing environments or interpreting a failure.
Prerequisites and hard constraints
The converter imports all of the following: PyTorch, torchvision, h5py,
TensorFlow, tensorflow_hub, and parse. The adjacent
TFHub/biggan_v1.py also imports NumPy and SciPy. The repository's normal
PyTorch dependencies therefore are not sufficient by themselves. Keep the
legacy TensorFlow/TFHub dependencies isolated from the normal training
environment.
The source uses TensorFlow 1.x graph/session APIs, including
tf.reset_default_graph(), tf.global_variables_initializer(), and
tf.Session(), plus the TF1-style hub.Module(...) API. TensorFlow 2.x is
not a drop-in replacement. Do not “fix” this route by silently substituting
TF2 or by claiming compatibility through tf.compat.v1 without separately
reviewing the TFHub module and the complete conversion behavior.
The converter has two important layout assumptions:
- Launch it from the
TFHubdirectory, for examplecd /path/to/BigGAN-PyTorch/TFHub. It imports the siblingbiggan_v1.pyand appends..to find the repository-levelBigGAN.py. Running from another directory can produce relative-import or module-path failures. DEVICEis hard-coded tocuda. Conversion itself reads weights and builds a PyTorch generator, but the optional sample path moves the generator and tensors to CUDA. There is no supported CPU sampling fallback in this script.
Operational outline
- Choose one resolution first. The
--resolution/-rflag accepts exactly128,256, or512. Omitting it converts all three in sequence. - Ensure the TFHub URL can be reached, or place the matching intermediate
biggan-<resolution>.h5in the selected weights directory. If the HDF5 exists and--redownloadis absent, the converter reuses it without contacting TFHub. - Run
converter.pyfromTFHub. It loads the module withtensorflow_hub, initializes the TF graph, writes every TF global variable to HDF5, maps the HDF5 variables through the legacybiggan_v1.pymodel andconvert_from_v1, then instantiates the currentBigGAN.Generator. - It saves the converted generator state dictionary as
biggan-<resolution>.pthunder--weights_dir. This is not a complete checkpoint containing optimizer, discriminator, or EMA training objects. - If
--generate_samplesis supplied, it samples random latent vectors and random ImageNet class ids on CUDA and writesbiggan<resolution>_samples.jpgunder--samples_dir. Use--parallelonly when the visible GPUs and the legacynn.parallel.data_parallelpath are appropriate. - Treat output existence as only a file-level check. A meaningful acceptance
check requires loading the intended state dictionary into the matching
current generator and visually or numerically checking generated images;
neither conversion nor
strict=Falseloading proves semantic equivalence.
Truncation limitation
The TFHub README explicitly says that this port is currently set up to run
without truncation. The converter's generate_sample does not call
biggan_v1.truncated_z_sample; it uses torch.randn and does not establish
standing statistics for truncation levels. The missing per-truncation standing
statistics mean that truncation curves or quality claims at non-default
truncation values are not reproduced by this route. Accumulate and validate
standing statistics separately before attempting truncation experiments, and
record that extra procedure with the result.
Scope and non-goals
This route covers only the checked-in TFHub conversion script and its adjacent legacy reference model. It does not modernize the code, download weights on the user's behalf, guarantee TF2 operation, provide a CPU implementation, create standing statistics, or certify image quality. Do not import this sub-skill into an automatic runtime router without preserving its explicit reference-only and not-runtime-verified warnings.
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).