Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
694e404b
Commit
694e404b
authored
Oct 16, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[WIP] move away all graph building logic
parent
ad5cb725
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
685 additions
and
521 deletions
+685
-521
tensorpack/graph_builder/_utils.py
tensorpack/graph_builder/_utils.py
+66
-1
tensorpack/graph_builder/distributed.py
tensorpack/graph_builder/distributed.py
+264
-0
tensorpack/graph_builder/training.py
tensorpack/graph_builder/training.py
+296
-2
tensorpack/train/distributed.py
tensorpack/train/distributed.py
+19
-221
tensorpack/train/multigpu.py
tensorpack/train/multigpu.py
+37
-294
tensorpack/train/simple.py
tensorpack/train/simple.py
+3
-3
No files found.
tensorpack/graph_builder/_utils.py
View file @
694e404b
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: utils.py
# File:
_
utils.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
import
copy
from
six.moves
import
zip
from
contextlib
import
contextmanager
import
operator
import
tensorflow
as
tf
from
..tfutils.common
import
get_op_tensor_name
from
..utils
import
logger
...
...
@@ -57,3 +62,63 @@ def get_sublist_by_names(lst, names):
raise
ret
.
append
(
lst
[
idx
])
return
ret
@
contextmanager
def
override_to_local_variable
(
enable
=
True
):
if
enable
:
with
tf
.
variable_scope
(
tf
.
get_variable_scope
(),
custom_getter
=
OverrideToLocalVariable
()):
yield
else
:
yield
class
OverrideToLocalVariable
(
object
):
"""
Ensures the created variable
is in LOCAL_VARIABLES and not GLOBAL_VARIBLES collection.
"""
def
__call__
(
self
,
getter
,
name
,
*
args
,
**
kwargs
):
if
'collections'
in
kwargs
:
collections
=
kwargs
[
'collections'
]
if
not
collections
:
collections
=
set
([
tf
.
GraphKeys
.
GLOBAL_VARIABLES
])
else
:
collections
=
set
(
collections
.
copy
())
collections
.
remove
(
tf
.
GraphKeys
.
GLOBAL_VARIABLES
)
collections
.
add
(
tf
.
GraphKeys
.
LOCAL_VARIABLES
)
kwargs
[
'collections'
]
=
list
(
collections
)
return
getter
(
name
,
*
args
,
**
kwargs
)
# Copied from https://github.com/tensorflow/benchmarks/blob/master/scripts/tf_cnn_benchmarks/variable_mgr.py
class
LeastLoadedDeviceSetter
(
object
):
""" Helper class to assign variables on the least loaded ps-device."""
def
__init__
(
self
,
worker_device
,
ps_devices
):
"""
Args:
worker_device: the device to use for compute ops.
ps_devices: a list of device to use for Variable ops.
"""
self
.
ps_devices
=
ps_devices
self
.
worker_device
=
worker_device
self
.
ps_sizes
=
[
0
]
*
len
(
self
.
ps_devices
)
def
__call__
(
self
,
op
):
def
sanitize_name
(
name
):
# tensorflow/tensorflow#11484
return
tf
.
DeviceSpec
.
from_string
(
name
)
.
to_string
()
if
op
.
device
:
return
op
.
device
if
op
.
type
not
in
[
'Variable'
,
'VariableV2'
]:
return
sanitize_name
(
self
.
worker_device
)
device_index
,
_
=
min
(
enumerate
(
self
.
ps_sizes
),
key
=
operator
.
itemgetter
(
1
))
device_name
=
self
.
ps_devices
[
device_index
]
var_size
=
op
.
outputs
[
0
]
.
get_shape
()
.
num_elements
()
self
.
ps_sizes
[
device_index
]
+=
var_size
return
sanitize_name
(
device_name
)
tensorpack/graph_builder/distributed.py
0 → 100644
View file @
694e404b
This diff is collapsed.
Click to expand it.
tensorpack/graph_builder/training.py
View file @
694e404b
This diff is collapsed.
Click to expand it.
tensorpack/train/distributed.py
View file @
694e404b
This diff is collapsed.
Click to expand it.
tensorpack/train/multigpu.py
View file @
694e404b
This diff is collapsed.
Click to expand it.
tensorpack/train/simple.py
View file @
694e404b
...
...
@@ -7,9 +7,9 @@ from .base import Trainer
from
..utils
import
logger
from
..graph_builder.input_source
import
FeedInput
,
QueueInput
from
..graph_builder.training
import
Simple
Graph
Builder
from
..graph_builder.training
import
SimpleBuilder
__all__
=
[
'SimpleTrainer'
]
__all__
=
[
'SimpleTrainer'
,
'QueueInputTrainer'
]
class
SimpleTrainer
(
Trainer
):
...
...
@@ -46,7 +46,7 @@ class SimpleTrainer(Trainer):
self
.
model
.
build_graph
(
inputs
)
return
self
.
model
.
get_cost
()
self
.
train_op
=
Simple
Graph
Builder
()
.
build
(
self
.
_input_source
,
get_cost
,
self
.
model
.
get_optimizer
)
self
.
train_op
=
SimpleBuilder
()
.
build
(
self
.
_input_source
,
get_cost
,
self
.
model
.
get_optimizer
)
self
.
config
.
callbacks
.
extend
(
cbs
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment