Port the super-resolution PixelShuffle + PSNR probe to Modal
The workspace contains superres_workflow.py, distilled from
pytorch-examples/super_resolution/model.py and main.py.
Net(upscale_factor) is the sub-pixel CNN: four Conv2d layers followed by
nn.PixelShuffle(upscale_factor). The last conv produces
upscale_factor ** 2 channels which the pixel shuffle interleaves into the
spatial dimension, taking (B, 1, H, W) to (B, 1, H * r, W * r).
The first three conv weights use orthogonal init with the ReLU gain
(init.calculate_gain('relu')); the last conv uses orthogonal init with the
default gain (matching the original code).
run_workflow(seed, upscale_factor, low_res) builds the Net, samples a
seeded (1, 1, low_res, low_res) low-resolution image in [0, 1],
generates a nearest-neighbor upsample of the same image as a reference HR
target, runs the model forward, and computes PSNR
(10 * log10(1 / MSE)) against that reference.
It returns {"output_shape", "mean", "std", "psnr_db"}.
What to deliver
Write /app/solution/modal_app.py from scratch with:
A module-level Modal app.
A module-level Modal Function object named run_case.
run_caseremote invocation (case) returns the same dict as the reference
run_workflow.
The Modal Image must include PyTorch. The workflow is CPU-only.
Case shape
python
case = {"seed": int, "upscale_factor": int, "low_res": int}
Match the seeding exactly: torch.manual_seed(seed) before constructing the
Net (so orthogonal init is reproducible), then torch.manual_seed(seed + 1)
before sampling the LR image. Use torch.no_grad() for the forward.
Capability contract
Expose the workflow as a single Modal remote function: define run_case as an @app.function so the harness can invoke it with run_case.remote(case).