Skip to content

Commit 81fa559

Browse files
authored
Merge pull request #17 from kengz/docs
fix: docs and demo examples
2 parents 04c4c2e + a105b12 commit 81fa559

File tree

9 files changed

+56
-24
lines changed

9 files changed

+56
-24
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,19 @@ File: [torcharc/example/spec/compact/mlp.yaml](torcharc/example/spec/compact/mlp
290290
# mlp:
291291
# Sequential:
292292
# - LazyLinear:
293-
# out_features: 128
294-
# - ReLU:
295-
# - LazyLinear:
296-
# out_features: 128
293+
# out_features: 64
297294
# - ReLU:
298295
# - LazyLinear:
299296
# out_features: 64
300297
# - ReLU:
301298
# - LazyLinear:
302299
# out_features: 32
303300
# - ReLU:
301+
# - LazyLinear:
302+
# out_features: 16
303+
# - ReLU:
304304

305-
# the above is equivalent to the compact spec below
305+
# the above can be written compactly as follows
306306

307307
modules:
308308
mlp:
@@ -396,7 +396,7 @@ File: [torcharc/example/spec/compact/conv.yaml](torcharc/example/spec/compact/co
396396
# - LazyLinear:
397397
# out_features: 10
398398

399-
# the above is equivalent to the compact spec below
399+
# the above can be written compactly as follows
400400

401401
modules:
402402
conv:

images/dlrm.png

24 KB
Loading

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "torcharc"
3-
version = "2.1.0"
3+
version = "2.1.1"
44
description = "Build PyTorch models by specifying architectures."
55
readme = "README.md"
66
requires-python = ">=3.12"

torcharc/example/notebook/demo.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@
66
import torcharc
77

88
# ================================================
9-
# Example: build model from spec file
9+
# To visualize model in Tensorboard, use the following
10+
# from torch.utils.tensorboard import SummaryWriter
11+
12+
# writer = SummaryWriter(log_dir="tb_logs/mlp")
13+
# writer.add_graph(model, x)
14+
# writer.close()
1015

16+
17+
# ================================================
18+
# Example: build model from spec file
1119
filepath = Path(".") / "torcharc" / "example" / "spec" / "basic" / "mlp.yaml"
1220

1321
# The following are equivalent:
@@ -52,6 +60,7 @@
5260
# )
5361
# )
5462

63+
5564
# ================================================
5665
# Example: MLP (Lazy)
5766
# PyTorch Lazy layers will infer the input size from the first forward pass. This is recommended as it greatly simplifies the model definition.
@@ -95,6 +104,30 @@
95104
model
96105

97106

107+
# ================================================
108+
# Example: MLP (Compact)
109+
model = torcharc.build(torcharc.SPEC_DIR / "compact" / "mlp.yaml")
110+
111+
# Run the model and check the output shape
112+
x = torch.randn(4, 128)
113+
y = model(x)
114+
assert y.shape == (4, 16)
115+
116+
model
117+
118+
119+
# ================================================
120+
# Example: Conv (Compact)
121+
model = torcharc.build(torcharc.SPEC_DIR / "compact" / "conv_classifier.yaml")
122+
123+
# Run the model and check the output shape
124+
x = torch.randn(4, 1, 28, 28)
125+
y = model(x)
126+
assert y.shape == (4, 10)
127+
128+
model
129+
130+
98131
# ================================================
99132
# Example: Reuse syntax: Stereo Conv
100133
# To use the same module for many passes, specify with the reuse syntax in graph spec: <module>~<suffix>.

torcharc/example/spec/compact/conv.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# - Dropout:
2424
# p: 0.1
2525

26-
# the above is equivalent to the compact spec below
26+
# the above can be written compactly as follows
2727

2828
modules:
2929
conv:

torcharc/example/spec/compact/conv_classifier.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
# - LazyLinear:
2929
# out_features: 10
3030

31-
# the above is equivalent to the compact spec below
31+
# the above can be written compactly as follows
3232

3333
modules:
3434
conv:

torcharc/example/spec/compact/mlp.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
# mlp:
33
# Sequential:
44
# - LazyLinear:
5-
# out_features: 128
6-
# - ReLU:
7-
# - LazyLinear:
8-
# out_features: 128
5+
# out_features: 64
96
# - ReLU:
107
# - LazyLinear:
118
# out_features: 64
129
# - ReLU:
1310
# - LazyLinear:
1411
# out_features: 32
1512
# - ReLU:
13+
# - LazyLinear:
14+
# out_features: 16
15+
# - ReLU:
1616

17-
# the above is equivalent to the compact spec below
17+
# the above can be written compactly as follows
1818

1919
modules:
2020
mlp:

torcharc/example/spec/compact/mlp_classifier.yaml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
# mlp:
33
# Sequential:
44
# - LazyLinear:
5-
# out_features: 128
6-
# - ReLU:
7-
# - LazyLinear:
8-
# out_features: 128
5+
# out_features: 64
96
# - ReLU:
107
# - LazyLinear:
118
# out_features: 64
129
# - ReLU:
1310
# - LazyLinear:
1411
# out_features: 32
1512
# - ReLU:
13+
# - LazyLinear:
14+
# out_features: 16
15+
# - ReLU:
1616
# classifier:
1717
# LazyLinear:
1818
# out_features: 10
1919

20-
# the above is equivalent to the compact spec below
20+
# the above can be written compactly as follows
2121

2222
modules:
2323
mlp:
@@ -35,7 +35,6 @@ modules:
3535
graph:
3636
input: x
3737
modules:
38-
# mlp: [x]
39-
# classifier: mlp
40-
classifier: [x]
38+
mlp: [x]
39+
classifier: [mlp]
4140
output: classifier

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)