提交 1efddab2 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Changed default compiledir under Windows

This change was advocated by Sebastian Urban, who explained: When you use roaming profiles in a domain environment the contents of the user profile directory C:\user\xxx are transferred (copied) from a file server at login. Login will become slow when many temporary files are stored in this directory. Therefore they should be stored in C:\user\xxx\appdata\local because this directory is not synchronized with a file server. theanorc can stay where it is, because it should roam with the user profile. This commit actually changes `config.home` rather than `config.base_compiledir`, because it is likely that if Theano ever wants to save more data files (in addition to compiled C modules), the same remark would apply. At the same time, `config.home` is being changed to be the home directory for Theano files, rather than the user home directory. It was not used anywhere in Theano except to define the location of the compilation directory, so there was no reason to keep a pointer to the user home directory while moving the Theano compiled files to another location. In order for this change to be safe, an error is raised if a user attempts to redefine `config.home` without also changing the location of the compilation directory. Otherwise, Theano files would be compiled in the parent of the intended folder (if the user is not aware of this change). Finally, note that currently, having both `config.home` and `config.base_compiledir` is redundant, since `home` is only used to define the default value of `base_compiledir`. So we could just decide to get rid of `home`.
上级 d3a51f4f
......@@ -100,8 +100,9 @@ case if ``borrow`` was True, the thunk would be allowed to reuse (or
.. note::
Compiled libraries are stored within a specific compilation directory,
which by default is set to ``$HOME/.theano/compiledir_xxx``, where
``xxx`` identifies the platform. It may be manually set to a different
location either by setting :attr:`config.compiledir` or
``xxx`` identifies the platform (under Windows the default location
is instead ``$LOCALAPPDATA\Theano\compiledir_xxx``). It may be manually set
to a different location either by setting :attr:`config.compiledir` or
:attr:`config.base_compiledir`, either within your Python script or by
using one of the configuration mechanisms described in :mod:`config`.
......
......@@ -275,13 +275,21 @@ import theano and print the config variable, as in:
.. attribute:: home
Default: env-variable $HOME
Default: On Linux: $HOME/.theano. On Windows: $LOCALAPPDATA\\Theano
This is used to compute the compiledir and base_compiledir attributes
This is the base directory where all Theano files are stored. Currently,
the only files being stored are compiled C modules, and thus changing ``home``
is similar to changing ``base_compiledir`` (described below).
Note however that ``home`` used to have a different meaning in previous
versions of Theano (up to 0.4.1), and to make sure its new meaning is
understood, it is currently forbidden to change ``home`` without also
changing either ``base_compiledir`` or ``compiledir``.
This flag's value cannot be modified during the program execution.
.. attribute:: base_compiledir
Default: $HOME/.theano
Default: ``config.home``
This directory stores the architecture-dependent compilation directories.
......@@ -289,7 +297,7 @@ import theano and print the config variable, as in:
.. attribute:: compiledir
Default: $HOME/.theano/<arch-identifier>
Default: ``config.base_compiledir``/<arch-identifier>
This directory stores dynamically-compiled modules for a particular
architecture.
......
import os
import subprocess
import logging
import subprocess
import sys
from theano.configparser import TheanoConfigParser, AddConfigVar, EnumStr, StrParam, IntParam, FloatParam, BoolParam
......@@ -131,9 +132,17 @@ def get_home_dir():
assert home is not None
return home
# On Windows we should avoid writing temporary files to a directory that is
# part of the roaming part of the user profile. Instead we use the local part
# of the user profile, when available.
if sys.platform == 'win32' and os.getenv('LOCALAPPDATA') is not None:
default_home = os.path.join(os.getenv('LOCALAPPDATA'), 'Theano')
else:
default_home = os.path.join(get_home_dir(), '.theano')
AddConfigVar('home',
"User home directory",
StrParam(get_home_dir()),
"Home directory for Theano files",
StrParam(default_home, allow_override=False),
in_c_key=False)
AddConfigVar('nocleanup',
......
import cPickle
import errno
import os
import platform
import re
import sys
import warnings
import theano
from theano.configparser import config, AddConfigVar, ConfigParam, StrParam
......@@ -51,28 +51,45 @@ def filter_compiledir(path):
return path
# TODO Using the local user profile on Windows is currently disabled as it
# is not documented yet, and may break some existing code. It will be enabled
# in a future code update.
if False and sys.platform == 'win32':
# On Windows we should not write temporary files to a directory
# that is part of the roaming part of the user profile. Instead
# we use the local part of the user profile.
basecompiledir = os.path.join(os.environ['LOCALAPPDATA'], 'theano')
else:
basecompiledir = os.path.join(config.home, '.theano')
AddConfigVar('base_compiledir',
"arch-independent cache directory for compiled modules",
StrParam(basecompiledir, allow_override=False))
StrParam(config.home, allow_override=False))
default_compiledir = os.path.join(
os.path.expanduser(config.base_compiledir),
default_compiledirname())
AddConfigVar('compiledir',
"arch-dependent cache directory for compiled modules",
ConfigParam(
os.path.join(
os.path.expanduser(config.base_compiledir),
default_compiledirname()),
filter=filter_compiledir,
allow_override=False))
ConfigParam(default_compiledir,
filter=filter_compiledir,
allow_override=False))
# The role of `config.home` was changed compared to Theano 0.4.1. It used to
# be the location of the user home directory. Now, it directly points to the
# directory where Theano should save its own data files. Typically, the
# difference is that it now includes the '.theano' folder, while it used to be
# the parent of that folder. In order for this change to be safe, we currently
# prevent people from changing `config.home` unless they also change
# the compilation directory.
if (config.home != theano.configdefaults.default_home and
config.base_compiledir == config.home and
# We need to compare to the `real` path because this is what is used in
# `filter_compiledir`.
config.compiledir == os.path.realpath(default_compiledir)):
# The user changed `config.home` but is still using the default values for
# `config.base_compiledir` and `config.compiledir`.
raise RuntimeError(
'You manually set your Theano home directory (to %s), but kept '
'the default compilation directory. Please note that the meaning '
'of the `home` directory was changed: it is now the base '
'directory for all Theano files, instead of being its parent '
'directory. To get rid of this error, please set the '
'`base_compiledir` config option to the directory you want '
'compiled files to be stored into (for instance: %s).' % (
config.home,
os.path.join(config.home, '.theano')))
def print_compiledir_content():
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论