File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,54 @@ A Stephen Fox endeavor to become an Applied AI Scientist.
2727
2828---
2929
30+ ## Usage
31+
32+ ### Installation
33+
34+ ` pip install morph-py `
35+
36+ ### Code Example
37+
38+ ``` python
39+ import morph
40+
41+ morph_optimizer = None
42+ # train loop
43+ for e in range (epoch_count):
44+
45+ for input , target in dataloader:
46+ optimizer.zero_grad() # optional: zero gradients or don't...
47+ output = model(input )
48+
49+ loss = loss_fn(output, target)
50+ loss.backward()
51+ optim.step()
52+
53+
54+ # setup for comparing the morphed model
55+ if morph_optimizer:
56+ morph_optimizer.zero_grad()
57+ morph_loss = loss_fn(morph_model(input ), target)
58+
59+ logging.info(f ' Morph loss - Standard loss = { morph_loss - loss} ' )
60+
61+ morph_loss.backward()
62+ morph_optimizer.step()
63+
64+
65+ # Experimentally supported: Initialize our morphing halfway training
66+ if e == epoch_count // 2 :
67+ # if you want to override your model
68+ model = morph.once(model)
69+
70+ # if you want to compare in parallel
71+ morph_model = morph.once(model)
72+
73+ # either way, you need to tell your optimizer about it
74+ morph_optimizer = init_optimizer(params = morph_model.parameters())
75+
76+ ```
77+
3078## What is Morph.py?
3179
3280Morph.py is a Neural Network Architecture Optimization toolkit targeted at Deep Learning researchers
Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ def main():
2020
2121 # get back the class that will do work
2222 morphed = net .Morph (my_model , epochs = 5 , dataloader = my_dataloader )
23+
24+ # TODO: we need your loss function, but this is currentry __unsupported__
2325 morphed .run_training ()
2426
2527
You can’t perform that action at this time.
0 commit comments