Skip to content

Commit

Permalink
Merge branch 'release-1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Novikov committed Jan 8, 2018
2 parents 52f04b6 + 0246ecb commit ae67484
Show file tree
Hide file tree
Showing 54 changed files with 6,061 additions and 457 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Set default charset
[*.py]
charset = utf-8

# 2 space indentation (TF style)
[*.py]
indent_style = space
indent_size = 2

[{.travis.yml}]
indent_style = space
indent_size = 2
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@

# Python egg metadata, regenerated from source files by setuptools.
/*.egg-info

# Documentation build files.
/docs/_build/

# Test coverage results.
.coverage

# Mac DS_Store files
.DS_Store

# IPython Notebook checkpoints
.ipynb_checkpoints
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
dist: trusty
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
env:
matrix:
- TF_VERSION=1.0
- TF_VERSION=1.1
- TF_VERSION=1.2
- TF_VERSION=1.3
- TF_VERSION=1.4
# command to install dependencies
install:
# Python 2.7 has very old pip by default that doesn't have tensorflow.
- pip install numpy tensorflow==$TF_VERSION
- pip install coveralls
# command to run tests
script:
nosetests --logging-level=WARNING --with-coverage --cover-package=t3f
after_success:
coveralls
43 changes: 42 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,47 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [1.0.0] - 2018-01-08
### Added
- API reference documentation.
- Coveralls test coverage.
- add_projected function for adding tensors from the same tangent space.
- add_n_projected function.
- Test TF 1.0-1.4
- Test Python 2.7, 3.4, 3.5, 3.6
- tf.kronecker module for working with Kornecker product matrices (TT-matrices of TT-rank 1).
- Example Jupyter notebooks with basic functionality, TensorNet (training neural networks with params in the TT-format), Riemannian optimization, and tensor completion.
- A profiler for basic operations on CPU and GPU.
- approximate.add_n function for adding together a batch of tensors and rounding after each summation.
- Manually import all the relevant function in __init__ and avoid importing internal tools.
- gather_nd for gathering several elements from a TT-objects at once.
- Overload operations to support `a - b`, `a + -b`, `0.4 * a`.
- Add complexities of some functions into the docstrings.

### Changed
- Speed improvements (in particular to quadratic_form).
- Bug fixes.
- Multiplication by a number uniformly multiplies all cores (improved stability for large tensors).
- Better test coverage.

## [0.3.0] - 2017-04-20
### Added
- Python 3 support.
- Speed improvements.
- Bug fixes.
- Travis CI.
- project_matmul -- fast projection of matrix-by-vector product.
- pairwise_flat_inner_projected -- fast pairwise dot products between projections on the same tangent space.
- multiply_along_batch_dim
- Support for indexing with placeholders or tf.Tensors.
- Support for t3f.cast(batch_tt).
- A function to replace tf.svd by np.svd.

### Changed
- Better Frobenius norm implementation (via QR).
- Riemannian projection API: now it's project(what, where).


## [0.2.0] - 2017-03-23
### Added
- (Partial) support for batches of TT-tensors.
Expand Down Expand Up @@ -33,4 +74,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

[Unreleased]: https://github.com/Bihaqo/t3f/compare/master...develop
[0.2.0]: https://github.com/Bihaqo/t3f/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/Bihaqo/t3f/compare/f24409508...0.1.0
[0.1.0]: https://github.com/Bihaqo/t3f/compare/f24409508...0.1.0
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2017 Alexander Novikov, Pavel Izmailov, Ivan Oseledets, Mikhail Trofimov
Copyright 2017 Alexander Novikov, Pavel Izmailov, Ivan Oseledets, Mikhail Trofimov, Valentin Khrulkov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
67 changes: 26 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
[![Build Status](https://travis-ci.org/Bihaqo/t3f.svg?branch=develop)](https://travis-ci.org/Bihaqo/t3f)
[![Coverage Status](https://coveralls.io/repos/github/Bihaqo/t3f/badge.svg?branch=develop)](https://coveralls.io/github/Bihaqo/t3f?branch=develop)

TensorFlow implementation of the Tensor Train (TT) -Toolbox.

# API
API is available via [readthedocs](https://t3f.readthedocs.io/en/latest/).

# Installation
First, [install TensorFlow](https://www.tensorflow.org/install/) v1 or higher. Then simply run
T3f assumes you have a working TensorFlow installation, supported versions are from 1.0 to 1.4 (see [here](https://www.tensorflow.org/versions/r1.4/install/) for TF 1.4 installation instructions).
We don't include it into pip requirements since the installation of TensorFlow varies depending on your setup.
Then simply run
```bash
pip install t3f
```
Expand Down Expand Up @@ -46,7 +54,7 @@ sum_round = t3f.round(t3f.add(a, b_tt), max_tt_rank=2)
# Inner product (sum of products of all elements).
a = t3f.random_tensor((3, 2, 2), tt_rank=3)
b = t3f.random_tensor((3, 2, 2), tt_rank=4)
inner_prod = t3f.tt_tt_flat_inner(a, b)
inner_prod = t3f.flat_inner(a, b)
```

### Matrix operations
Expand All @@ -60,49 +68,26 @@ matvec = t3f.matmul(A, b)
b_dense = tf.random_normal((18, 1))
matvec2 = t3f.matmul(A, b_dense)
```
# More examples
For more examples (e.g. how to build neural networks or how to do Riemannian optimization) see ```examples``` folder.

# Benchmarking
Here are the results im ms of benchmarking T3F on CPU and GPU and comparing against the [TTPY library](https://github.com/oseledets/ttpy)
<img src="examples/profile/results.png" height="200">

# TensorNet example
As an example lets create a neural network with a TT-matrix as a fully-connected layer:
```python
def build_tt_model(x):
# A 784 x 625 TT-matrix.
matrix_shape = ((4, 7, 4, 7), (5, 5, 5, 5))
tt_W_1 = t3f.get_variable('tt_W_1', initializer=t3f.random_matrix(matrix_shape))
h_1 = tf.nn.relu(t3f.matmul(tt_W_1, x))
W_2 = tf.get_variable('W_2', shape=[625, 10])
y = tf.matmul(W_2, h_1)
return y
```

If you want to start from already trained network and compress its fully-connected layer, you may load the network, find the closes approximation of the existing layer matrix in the TT-format, and then finetune the model
```python
y = build_tt_model(x)
with tf.variable_scope("", reuse=True):
tt_W_1 = t3f.get_tt_variable('tt_W_1')
W_1 = tf.get_variable('W_1', shape=[784, 625])
tt_init_op = t3f.initialize_from_tensor(tt_W_1, W_1)
loss = tf.nn.softmax_cross_entropy_with_logits(y, labels)
train_step = tf.train.Adam(0.01).minimize(loss)
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
restore_all_saved(sess, 'checkpoint/path')
sess.run(tt_init_op)
# Finally do the finetuning.
...
```
where
```python
def restore_all_saved(sess, path):
reader = tf.train.NewCheckpointReader(path)
var_names_in_checkpoint = reader.get_variable_to_shape_map().keys()
with tf.variable_scope('', reuse=True):
vars_in_checkpoint = [tf.get_variable(name) for name in var_names_in_checkpoint]
restorer = tf.train.Saver(var_list=vars_in_checkpoint)
restorer.restore(sess, path)
```
For more details see ```examples/profile``` folder.

# Tests
```bash
nosetests --logging-level=WARNING
```

# Building API documentation
The documentation is build by sphinx and hosted on readthedocs.org. To rebuild the documentation, install sphinx and compile the docs by
```bash
cd docs
make html
```

# Other implementations
There are also implementations of the TT-toolbox in [plain Python](https://github.com/oseledets/ttpy) and [Matlab](https://github.com/oseledets/TT-Toolbox).
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = t3f
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Loading

0 comments on commit ae67484

Please sign in to comment.