Skip to content

Automated code review — 2026-06-03 #61

Description

@bes-dev

Automated Code Review Findings

  1. [configs/model_zoo.json:4] [SECURITY] All model checksums use MD5, which is cryptographically broken and susceptible to collision attacks. A malicious or corrupted checkpoint could pass MD5 verification. SHA-256 should be used instead to ensure model integrity.
  2. [convert_rosinality_ckpt.py:78] [SECURITY] torch.load() called without weights_only=True. Pickle-based deserialization of untrusted checkpoint files can execute arbitrary Python code during loading.
  3. [core/model_zoo.py:10] [SECURITY] torch.load() called without weights_only=True on an arbitrary user-supplied file path ('name' parameter). PyTorch's default pickle-based deserialisation can execute arbitrary Python code if the checkpoint file is malicious or has been tampered with.
  4. [core/utils.py:28] [SECURITY] Checkpoint path constructed as f"/tmp/{name}" using an externally-supplied 'name' value from the model zoo JSON. A path-traversal payload in 'name' (e.g. "../../home/user/.bashrc") would cause gdown to overwrite files outside /tmp.
  5. [core/utils.py:30] [SECURITY] torch.load() called without weights_only=True on a file downloaded from an external URL. Pickle deserialisation of untrusted checkpoint data can lead to arbitrary code execution.
  6. [configs/model_zoo.json:20] [CORRECTNESS] Key 'mobilestylegan_ffhq_v1.ckpt' has a mismatched 'name' field value 'mobilestylegan_ffhq.ckpt' (no '_v1' suffix). If any download or lookup logic uses the JSON key as the expected on-disk filename, the file will never be found under that key name, silently causing a download or load failure.
  7. [convert_rosinality_ckpt.py:51] [CORRECTNESS] Potential UnboundLocalError: c_out is only assigned inside the while loop body. If the loop never executes (e.g. empty/malformed checkpoint), channels.append(c_out) on line 51 raises UnboundLocalError.
  8. [core/distiller.py:92] [CORRECTNESS] validation_step calls self.student() twice with identical inputs (lines 88 and 92). The first result is used only for inception features; the second is used for the loss. The first forward pass is redundant and wasteful, but more importantly introduces numerical non-determinism if dropout or random noise is active.
  9. [core/distiller.py:146] [CORRECTNESS] In the 'else' branch of make_sample(), var is sampled with shape (self.wsize, style_dim) instead of (self.cfg.batch_size, style_dim), producing a style tensor of batch size 1. All other branches produce batch_size samples, causing shape mismatches in loss computations for this branch.
  10. [core/loss/perceptual_loss.py:15] [CORRECTNESS] PerceptualNetwork initialises the VGG backbone with the deprecated 'pretrained=True' keyword. In torchvision >= 0.13 this parameter is removed; the correct API is weights=VGG16_Weights.DEFAULT. Code will raise a TypeError on recent torchvision versions.
  11. [core/model_zoo.py:6] [CORRECTNESS] json.load(open(zoo_path)) never closes the file handle. Under high load or on Windows this can exhaust file descriptors. Should use 'with open(zoo_path) as f: zoo = json.load(f)'.
  12. [core/models/modules/ops/fused_act.py:35] [CORRECTNESS] 'raise NotImplemented' raises a TypeError at runtime because NotImplemented is a singleton value, not an exception class. The intended exception is NotImplementedError. This means callers on non-CPU, non-CUDA devices get an uninformative TypeError instead of NotImplementedError.
  13. [core/models/modules/ops/upfirdn2d.py:17] [CORRECTNESS] Same 'raise NotImplemented' bug as in fused_act.py — raises TypeError instead of NotImplementedError for non-CPU, non-CUDA inputs.
  14. [core/models/synthesis_network.py:95] [CORRECTNESS] In SynthesisNetwork.forward(), '_style' is computed to correctly slice the style tensor for each block (W+ space), but 'style' (the full, un-sliced tensor) is passed to m() instead. Every SynthesisBlock therefore always receives the full style and internally indexes style[:, 0, :], breaking per-block style mixing entirely.
  15. [evaluate_fid.py:131] [CORRECTNESS] Double division by 255: TF.ToTensor() already converts PIL images to float tensors in [0,1]. Both the BatchNorm fitting loop (line 131) and the inference loop (line 144) divide by 255 again, producing near-zero values and completely corrupting the FID computation.
  16. [evaluate_fid.py:137] [CORRECTNESS] start_idx is assigned but never used. It appears to be a leftover from a refactor where it was intended to track array offsets; its absence means nothing is broken here, but the variable is dead code that signals an incomplete implementation.
  17. [generate.py:23] [CORRECTNESS] generate.py never creates the output directory before writing images. If --output-path does not exist, cv2.imwrite silently fails (returns False) without raising an exception, producing no output and no error.
  18. [requirements.txt:9] [CORRECTNESS] requirements.txt uses the git:// protocol (git+git://github.com/...) which GitHub deprecated and disabled. Installations will fail on modern systems; should use git+https://github.com/... instead.
  19. [train.py:47] [CORRECTNESS] raise "Unknown export format." raises a string literal, not an exception. In Python 3 this causes TypeError: exceptions must derive from BaseException at runtime, masking the intended error message.
  20. [compare.py:2] [STYLE] import os is unused in compare.py.
  21. [configs/template_cfg.json:1] [STYLE] 'stylemix_p' key is present in mobile_stylegan_ffhq.json but absent from template_cfg.json. The two configs are intended to share the same schema, so omitting a field from the template makes it non-obvious that style-mixing probability is configurable, and tools that merge or validate configs against the template will silently ignore it.
  22. [core/models/discriminator.py:3] [STYLE] discriminator.py relies on 'import math' being re-exported through 'from .modules.legacy import *'. There is no explicit 'import math' in discriminator.py itself. This is a fragile implicit dependency that will silently break if legacy.py ever removes its math import.
  23. [core/models/modules/idwt_upsample.py:5] [STYLE] Class name 'IDWTUpsaplme' is a typo ('Upsaplme' instead of 'Upsample'). Referenced in mobile_synthesis_block.py.
  24. [core/models/modules/multichannel_image.py:5] [STYLE] Class name 'MultichannelIamge' is a typo ('Iamge' instead of 'Image'). The misspelling propagates through modules/init.py and mobile_synthesis_network.py.
  25. [demo.py:2] [STYLE] import os is unused in demo.py.
  26. [generate.py:5] [STYLE] import numpy as np is unused in generate.py.
  27. [train.py:6] [STYLE] select_weights is imported but never used in train.py.
  28. [configs/template_cfg.json:16] [QUESTION] template_cfg.json leaves teacher network names as empty strings, which will cause silent or confusing runtime errors if a user instantiates a pipeline from the template without filling them in. Consider using a placeholder sentinel value (e.g. null or a comment-like string) and adding an explicit validation step.
  29. [core/distiller.py:97] [QUESTION] validation_epoch_end contains a TODO comment acknowledging that KID metric aggregation is incorrect in distributed (multi-GPU) training because pred/gt inception features are not gathered across devices. This silently produces wrong KID values whenever more than one GPU is used.
  30. [core/models/modules/modulated_conv2d.py:18] [QUESTION] The style_inv buffer in ModulatedConv2d (and ModulatedDWConv2d) is initialised with torch.randn and is never updated. Demodulation therefore uses a frozen random scale rather than the actual per-sample style, which is a deliberate approximation but differs from the standard StyleGAN2 demodulation. Is this the intended behaviour?
  31. [evaluate_fid.py:126] [QUESTION] evaluate_fid.py introduces a custom BatchNorm-based normalization layer trained on the input data before computing Inception activations. This deviates from the standard pytorch-fid pipeline (which uses fixed Inception preprocessing) and could produce non-comparable FID values vs. published benchmarks.

Generated on 2026-06-03 by automated-reviewer. Repository: bes-dev/MobileStyleGAN.pytorch.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions