Skip to content

Commit

Permalink
fix bug in root_variable_scope and in travis scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
haowen-xu committed Dec 17, 2018
1 parent 5ad3006 commit 2c6d2d9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ env:
- PYTHON_VERSION=3 TENSORFLOW_VERSION=1.5
- PYTHON_VERSION=2 TENSORFLOW_VERSION=1.12
- PYTHON_VERSION=3 TENSORFLOW_VERSION=1.12
- CORE_TESTS_ONLY=1
- PYTHON_VERSION=2 TENSORFLOW_VERSION=*
- PYTHON_VERSION=3 TENSORFLOW_VERSION=*
cache:
directories:
- /home/travis/.tfsnippet
Expand Down
2 changes: 1 addition & 1 deletion scripts/travis-docker-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pip install -r requirements-dev.txt
mkdir -p /root/.config/matplotlib
echo 'backend : Agg' > /root/.config/matplotlib/matplotlibrc

if [ "${CORE_TESTS_ONLY}" = "1" ]; then
if [ "${TENSORFLOW_VERSION}" = "*" ]; then
coverage run -m py.test \
tests/utils/test_reuse.py \
tests/utils/test_scope.py \
Expand Down
17 changes: 9 additions & 8 deletions scripts/travis-run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function runTest() {

echo "TFSnippet Tests
CORE_TESTS_ONLY=${CORE_TESTS_ONLY}
PYTHON_VERSION=${PY_VER}
TENSORFLOW_VERSION=${TF_VER}
RUN_EXAMPLES_TEST_CASE=${RUN_EXAMPLES_TEST_CASE}
Expand All @@ -23,21 +22,23 @@ function runTest() {
-e TRAVIS="${TRAVIS}" \
-e TRAVIS_JOB_ID="${TRAVIS_JOB_ID}" \
-e TRAVIS_BRANCH="${TRAVIS_BRANCH}" \
-e CORE_TESTS_ONLY="${CORE_TESTS_ONLY}" \
-e PYTHON_VERSION="${PYTHON_VERSION}" \
-e TENSORFLOW_VERSION="${TENSORFLOW_VERSION}" \
-e RUN_EXAMPLES_TEST_CASE="${RUN_EXAMPLES_TEST_CASE}" \
"${IMAGE_NAME}" \
bash "scripts/travis-docker-entry.sh"
}
if [[ "${CORE_TESTS_ONLY}" = "1" ]]; then
for PY_VER in 2 3; do

if [[ "${TRAVIS_BRANCH}" = "master" || "${TRAVIS_BRANCH}" = "develop" ]]; then
if [[ "${TENSORFLOW_VERSION}" = "*" ]]; then
for TF_VER in 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12; do
runTest "${PY_VER}" "${TF_VER}" "0";
done
done
else
if [[ "${TRAVIS_BRANCH}" = "master" || "${TRAVIS_BRANCH}" = "develop" ]]; then
runTest "${PYTHON_VERSION}" "${TENSORFLOW_VERSION}" "1";
else
runTest "${PYTHON_VERSION}" "${TENSORFLOW_VERSION}" "1";
fi
else
if [[ "${TENSORFLOW_VERSION}" != "*" ]]; then
runTest "${PYTHON_VERSION}" "${TENSORFLOW_VERSION}" "0";
fi
fi
18 changes: 15 additions & 3 deletions tfsnippet/utils/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import six
import tensorflow as tf
from tensorflow.python.ops import variable_scope as variable_scope_ops

from .doc_inherit import DocInherit
from .misc import camel_to_underscore
Expand Down Expand Up @@ -61,9 +62,20 @@ def root_variable_scope(**kwargs):
Args:
**kwargs: Named arguments for opening the root variable scope.
"""
with tf.variable_scope('', auxiliary_name_scope=False, **kwargs) as vs:
with tf.name_scope(None):
yield vs
# `tf.variable_scope` does not support opening the root variable scope
# from empty name. It always prepend the name of current variable scope
# to the front of opened variable scope. So we get the current scope,
# and pretend it to be the root scope.
scope = tf.get_variable_scope()
old_name = scope.name
try:
scope._name = ''
with variable_scope_ops._pure_variable_scope('', **kwargs) as vs:
scope._name = old_name
with tf.name_scope(None):
yield vs
finally:
scope._name = old_name


@DocInherit
Expand Down

0 comments on commit 2c6d2d9

Please sign in to comment.