Skip to content

Commit 7ac09be

Browse files
committed
- modified / to be the div operation for float and double tensors, and // for int-type tensors, such as
byte, long, int - updated README a bit
1 parent 0d90b40 commit 7ac09be

File tree

10 files changed

+3751
-3671
lines changed

10 files changed

+3751
-3671
lines changed

README.md

Lines changed: 49 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,42 @@
11
# pytorch
22
Wrappers to use torch and lua from python
33

4-
# What is implemented
4+
# What is python?
55

6-
See [Implemented.md](doc/Implemented.md)
6+
- create torch tensors, call operations on those, add them together, multiply them, and so on
7+
- create `nn` network modules, pass tensors into those, get the output, and so on
8+
- create your own lua class, call methods on that, pass in tensors
9+
- wrap numpy tensors in torch tensors
10+
11+
More info: [Implemented.md](doc/Implemented.md)
712

813
# Examples
914

10-
Examples of what is possible currently:
11-
* pytorch
12-
* pynn
13-
14-
Types supported currently:
15-
* FloatTensor
16-
* DoubleTensor
17-
* LongTensor
18-
* ByteTensor
19-
20-
(fairly easy to add others, since templated)
21-
22-
* (New!) you can also import your own lua class, and call methods on those :-)
23-
24-
# Requirements
25-
26-
- python should be in PATH
27-
- Cython should be installed, ie if you do `pip freeze`, you should see a list of libraries, and one of those should be `Cython`
28-
- torch should have been activated, ie something like `source ~/torch/install/bin/torch-activate.sh`
29-
- lua51 headers should be installed, ie something like `sudo apt-get install lua5.1 liblua5.1-dev`
30-
31-
# Unit-tests
32-
33-
Run:
34-
```
35-
./build.sh
36-
./run_tests.sh
37-
```
38-
39-
* [test](test) folder, containing test scripts
40-
* [tests_output.txt](test_outputs/tests_output.txt)
41-
42-
# pytorch, example using FloatTensor
15+
## pytorch, using FloatTensor
4316

4417
Run example script by doing:
4518
```
46-
./build.sh
19+
source ~/torch/install/bin/torch-activate
20+
cd pytorch
4721
./run.sh
4822
```
4923

50-
* [test_pytorch.py](test/test_pytorch.py)
51-
* [test_pytorch_output.txt](test_outputs/test_pytorch_output.txt)
24+
* Script is here: [test_pytorch.py](test/test_pytorch.py)
25+
* Output: [test_pytorch_output.txt](test_outputs/test_pytorch_output.txt)
5226

53-
# pynn
27+
## pynn
5428

5529
Run example script by doing:
5630
```
57-
./build.sh
31+
source ~/torch/install/bin/torch-activate
32+
cd pytorch
5833
./nn_run.sh
5934
```
6035

61-
* [test_pynn.py](test/test_pynn.py)
62-
* [test_pynn_output.txt](test_outputs/test_pynn_output.txt)
36+
* Script is here: [test_pynn.py](test/test_pynn.py)
37+
* Script output: [test_pynn_output.txt](test_outputs/test_pynn_output.txt)
6338

64-
# import your own class, and call methods on it
39+
## import your own lua class, call methods on it
6540

6641
- Create a lua class, like say [luabit.lua](simpleexample/luabit.lua)
6742
- it contains some methods, that we will call from Python
@@ -92,50 +67,57 @@ color: green
9267
## Pre-requisites
9368

9469
* Have installed torch, following instructions at [https://github.com/torch/distro](https://github.com/torch/distro)
95-
* Have installed 'nn', ie:
70+
* Have installed 'nn' torch module:
9671
```
9772
luarocks install nn
9873
```
9974
* Have installed python (tested with 2.7 and 3.4)
100-
* Have installed the following python libraries, ie do:
75+
* Have installed the following python libraries:
10176
```
10277
pip install numpy
10378
pip install Cython
10479
pip install Jinja2
10580
pip install pytest
10681
```
82+
- lua51 headers should be installed, ie something like `sudo apt-get install lua5.1 liblua5.1-dev`
10783

10884
## Procedure
10985

86+
Run:
11087
```
11188
git clone https://github.com/hughperkins/pytorch.git
11289
cd pytorch
90+
source ~/torch/install/bin/torch-activate
11391
./build.sh
11492
```
11593

116-
# How to add new methods
94+
# Unit-tests
11795

118-
## pytorch
96+
Run:
97+
```
98+
source ~/torch/install/bin/torch-activate
99+
cd pytorch
100+
./run_tests.sh
101+
```
119102

120-
* the C library methods are defined in the torch library in torch7 repo, in two files:
121-
* lib/TH/generic/THTensor.h
122-
* lib/TH/generic/THStorage.h
123-
* simply copy the appropriate declaration into [PyTorch.jinja2.pyx](src/PyTorch.jinja2.pyx), in the blocks that start `cdef extern from "THStorage.h":` or `cdef extern from "THTensor.h":`, as appropriate
124-
* note that this is a template file. The generated Cython .pyx file is [PyTorch.pyx](src/PyTorch.pyx)
125-
* and add an appropriate method into {{Real}}Storage class, or {{Real}}Tensor class
126-
* that's it :-)
103+
* The test scripts: [test](test)
104+
* The test output: [tests_output.txt](test_outputs/tests_output.txt)
127105

128-
You can have a look eg at the `narrow` method as an example
106+
# Python 2 vs Python 3?
129107

130-
Updates:
131-
* the cython class is now called eg `_{{Real}}Tensor` instead of `{{Real}}Tensor`. Then we create a pure Python class called `{{Real}}Tensor` around this, by inheriting from `_{{Real}}Tensor`, and providing no additional methods or properties. The pure Python class is monkey-patchable, eg by [PyClTorch](https://github.com/hughperkins/pycltorch)
132-
* the `cdef` properties and methods are now declared in [PyTorch.jinja2.pxd](src/PyTorch.jinja2.pxd). This means we can call these methods and properties from [PyClTorch](https://github.com/hughperkins/pycltorch)
133-
* note that [PyTorch.jinja2.pxd](src/PyTorch.jinja2.pxd) is a template file. The generated Cython .pxd file is [PyTorch.pxd](src/PyTorch.pxd)
134-
* the `THGenerator *` object is now available, at `globalState.generator`, and used by the various random methods, eg `_FloatTensor.bernoulli()`
108+
- pytorch is developed and maintained on python 3
109+
- you should be able to use it with python 2, as long as you include the following at the top of your scripts:
110+
```
111+
from __future__ import print_function, division
112+
```
135113

136-
## pynn
114+
# Maintainer guidelines
115+
116+
[Maintainer guidelines](doc/Maintainer_guidelines.md)
137117

138-
This has been simplified a bunch since before. We no longer try to wrap C++ classes around the lua, but just directly wrap Python classes around the Lua. The class methods and attributes are mostly generated dynamically, according to the results of querying hte lua ones. Mostly all we have to do is create classes with appropriate names, that derive from LuaClass. We might need to handle inheritance somehow in the future. At the moment, this is all handled really by PyTorchAug.py.
118+
# Versioning
119+
120+
[semantic versioning](http://semver.org/)
139121

140122
# Related projects
141123

@@ -144,6 +126,11 @@ This has been simplified a bunch since before. We no longer try to wrap C++ cla
144126

145127
# Recent news
146128

129+
26th February:
130+
* modified `/` to be the div operation for float and double tensors, and `//` for int-type tensors, such as
131+
byte, long, int
132+
* since the div change is incompatible with 1.0.0 div operators, jumping radically from `1.0.0` to `2.0.0-SNAPSHOT` ...
133+
147134
24th February:
148135
* added support for passing strings to methods
149136
* added `require`

doc/Maintainer_guidelines.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Maintainer guidelines
2+
3+
## How to add new methods
4+
5+
### pytorch
6+
7+
* the C library methods are defined in the torch library in torch7 repo, in two files:
8+
* lib/TH/generic/THTensor.h
9+
* lib/TH/generic/THStorage.h
10+
* simply copy the appropriate declaration into [PyTorch.jinja2.pyx](src/PyTorch.jinja2.pyx), in the blocks that start `cdef extern from "THStorage.h":` or `cdef extern from "THTensor.h":`, as appropriate
11+
* note that this is a template file. The generated Cython .pyx file is [PyTorch.pyx](src/PyTorch.pyx)
12+
* and add an appropriate method into {{Real}}Storage class, or {{Real}}Tensor class
13+
* that's it :-)
14+
15+
You can have a look eg at the `narrow` method as an example
16+
17+
Updates:
18+
* the cython class is now called eg `_{{Real}}Tensor` instead of `{{Real}}Tensor`. Then we create a pure Python class called `{{Real}}Tensor` around this, by inheriting from `_{{Real}}Tensor`, and providing no additional methods or properties. The pure Python class is monkey-patchable, eg by [PyClTorch](https://github.com/hughperkins/pycltorch)
19+
* the `cdef` properties and methods are now declared in [PyTorch.jinja2.pxd](src/PyTorch.jinja2.pxd). This means we can call these methods and properties from [PyClTorch](https://github.com/hughperkins/pycltorch)
20+
* note that [PyTorch.jinja2.pxd](src/PyTorch.jinja2.pxd) is a template file. The generated Cython .pxd file is [PyTorch.pxd](src/PyTorch.pxd)
21+
* the `THGenerator *` object is now available, at `globalState.generator`, and used by the various random methods, eg `_FloatTensor.bernoulli()`
22+
23+
### pynn
24+
25+
This has been simplified a bunch since before. We no longer try to wrap C++ classes around the lua, but just directly wrap Python classes around the Lua. The class methods and attributes are mostly generated dynamically, according to the results of querying hte lua ones. Mostly all we have to do is create classes with appropriate names, that derive from LuaClass. We might need to handle inheritance somehow in the future. At the moment, this is all handled really by PyTorchAug.py.
26+
27+

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def get_file_datetime(filepath):
120120

121121
setup(
122122
name='PyTorch',
123-
version='1.0.0',
123+
version='2.0.0',
124124
author='Hugh Perkins',
125125
author_email='hughperkins@gmail.com',
126126
description=(

0 commit comments

Comments
 (0)