Skip to content

Use list comprehension to create distinct ResBlock instances#6

Open
lkliu7 wants to merge 1 commit intodeep-learning-with-pytorch:mainfrom
lkliu7:unshare-refs
Open

Use list comprehension to create distinct ResBlock instances#6
lkliu7 wants to merge 1 commit intodeep-learning-with-pytorch:mainfrom
lkliu7:unshare-refs

Conversation

@lkliu7
Copy link
Copy Markdown
Contributor

@lkliu7 lkliu7 commented Apr 5, 2026

n_blocks * [ResBlock(...)] creates shared reference to single object; used comprehension to create blocks with independent parameters. Verify by checking that sum(p.numel() for p in model.parameters()) is identical for n_blocks=1, 10, 100 (75810) with the original code.
Downstream cell outputs (training loss, accuracy) will change when the notebook is re-run.

n_blocks * [ResBlock(...)] creates shared reference to single
object; used comprehension to create blocks with independent params.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant