-
Notifications
You must be signed in to change notification settings - Fork 7
/
Rakefile
108 lines (83 loc) · 2.35 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
require_relative './third/tensorflow-rakefile/tfrake.rb'
include TFRake
README_FILE = 'README.md'.freeze
define_tasks('qnd', define_pytest: false)
task_in_venv :pytest do
vsh 'cd examples/lib && . ./mnist.sh && fetch_dataset'
Dir.glob(['qnd/**/*_test.py', 'examples/**/*_test.py']).each do |file|
vsh :pytest, file
end
end
task_in_venv :script_test do
vsh 'python3 test/empty.py'
Dir.glob('test/*.py').each do |file|
vsh :python3, file, '-h'
end
distributed_oracle = 'distributed=yes python3 test/oracle.py'
vsh "#{distributed_oracle} -h"
# Worker hosts should not include a master host.
vsh('!', distributed_oracle.to_s,
'--master_host', 'localhost:4242',
'--worker_hosts', 'localhost:4242',
'--ps_hosts', 'localhost:5151',
'--task_type', 'job',
'--train_file', 'README.md',
'--eval_file', 'setup.py')
end
%i[mnist_simple mnist_distributed mnist_evaluate mnist_infer].each do |name|
task_in_venv name do
vsh "cd examples/#{name} && ./main.sh"
end
end
task_in_venv :mnist_full do |t|
[
nil,
%i[use_eval_input_fn],
# %i[use_serving_input_fn], # TODO: Enable this test when tensorflow/tensorflow #9923 is merged.
%i[use_dict_inputs],
%i[use_model_fn_ops],
%i[self_batch],
%i[self_filename_queue use_eval_input_fn]
].each do |flags|
vsh(
'cd', "examples/#{t.name}", '&&',
(flags && flags.map { |flag| "#{flag}=yes" }.join(' ')).to_s, './main.sh'
)
end
end
task test: %i[
pytest
script_test
mnist_simple
mnist_distributed
mnist_evaluate
mnist_infer
mnist_full
]
task :readme_examples do
md = File.read(README_FILE)
command_script = 'train.py'
library_script = 'mnist.py'
def read_example_file(file)
File.read(File.join('examples/mnist_simple', file)).strip
end
File.write(README_FILE, %(
#{md.match(/(\A.*## Examples)/m)[0]}
`#{command_script}` (command script):
```python
#{read_example_file command_script}
```
`#{library_script}` (module):
```python
#{read_example_file library_script}
```
With the code above, you can create a command with the following interface.
```
#{`#{IN_VENV} cd examples/mnist_simple && python3 #{command_script} -h`.strip}
```
Explore [examples](examples) directory for more information and see how to run
them.
#{md.match(/## Caveats.*\Z/m)[0].strip}
).lstrip)
end
task doc: %i[pdoc readme_examples]