Merge branch 'blis/ops14todo' of https://github.com/Microsoft/CNTK into blis/ops14todo

This commit is contained in:
William Darling 2016-05-03 17:44:22 +02:00
Родитель 4541bf3c2e 70c395492d
Коммит 889228ba9e
3 изменённых файлов: 47 добавлений и 23 удалений

Просмотреть файл

@ -91,14 +91,6 @@ class AbstractContext(with_metaclass(ABCMeta, object)):
self.precision = precision
self.input_nodes = set()
def __enter__(self):
_CONTEXT[self.name] = self
return self
def __exit__(self, exc_type, exc_value, exc_tb):
del _CONTEXT[self.name]
def _save_file(self, config_file_name, config_content, action_name):
'''
Writes the content of a config file on disk.
@ -113,7 +105,6 @@ class AbstractContext(with_metaclass(ABCMeta, object)):
'''
filename = os.path.join(self.directory, config_file_name)
filename = os.path.relpath(filename)
with open(filename, 'w') as out:
out.write(config_content)
@ -373,8 +364,12 @@ class LocalExecutionContext(AbstractContext):
self.model_path = os.path.join(self.model_dir, self.name)
self.output_filename_base = os.path.join(self.directory, CNTK_OUTPUT_FILENAME)
def __enter__(self):
_CONTEXT[self.name] = self
return self
def __exit__(self, exc_type, exc_value, exc_tb):
super(self.__class__, self).__exit__( exc_type, exc_value, exc_tb)
del _CONTEXT[self.name]
if self.clean_up:
sh.rmtree(self.directory)
@ -764,21 +759,29 @@ class DeferredExecutionContext(AbstractContext):
the machine that generated them.
Args:
name (str): context name
device_id (int): whether to use CPU (-1) or GPU if `device_id>=0`, in which case it denotes the GPU index
precision (str): either float or double
'''
def __init__(self, name,
def __init__(self,
device_id=-1,
precision="float",
clean_up=True):
super(self.__class__,self).__init__(name, device_id, precision)
self.model_path = os.path.join("$ModelDir$", self.name)
precision="float"):
self.device_id = device_id
self.precision = precision
self.input_nodes = set()
self.model_path = os.path.join("$ModelDir$", "model")
self.output_filename_base = os.path.join("$DataDir$", CNTK_OUTPUT_FILENAME)
self.config = []
self.actions = []
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, exc_tb):
pass
def _append_config(self, action_name, config_content):
'''
Append the config to the existing one
@ -866,17 +869,28 @@ class DeferredExecutionContext(AbstractContext):
node, input_map, backward_pass, action_name)
self._append_config(action_name, config_content)
def export(self):
def export(self, name):
'''
Exports the requested actions (via function calls like train()) to
a signle cntk configuration file that will be executed on the cluster
Returns:
name (str): context name, which is also the name of the output folder
that contains the configuration
filename to which the configuration has been exported
'''
filename = '%s.cntk' %self.name
self.directory = os.path.abspath(name)
if os.path.exists(self.directory):
print("Directory '%s' already exists" %
self.directory)
else:
os.mkdir(self.directory)
filename = '%s.cntk' %name
filename = os.path.join(self.directory, filename)
filename = os.path.relpath(filename)
with open(filename, 'w') as out:
out.write('\n'.join(self.config))

Просмотреть файл

@ -0,0 +1,10 @@
cntk.ops.tests package
======================
Module contents
---------------
.. automodule:: cntk.ops.tests
:members:
:undoc-members:
:show-inheritance:

Просмотреть файл

@ -4,7 +4,7 @@ cntk.utils package
Module contents
---------------
.. automodule:: cntk.utils
.. automodule:: cntk.utils.eval
:members:
:undoc-members:
:show-inheritance: