Torch

Torch is a scientific computing framework with wide support for machine learning algorithms that puts GPUs first. It is easy to use and efficient, thanks to an easy and fast scripting language, LuaJIT, and an underlying C/CUDA implementation.

A summary of core features:
  • a powerful N-dimensional array
  • lots of routines for indexing, slicing, transposing, …
  • amazing interface to C, via LuaJIT
  • linear algebra routines
  • neural network, and energy-based models
  • numeric optimization routines
  • Fast and efficient GPU support
  • Embeddable, with ports to iOS and Android backends
The easiest way to learn and experiment with Torch is by starting an interactive session (also known as the torch read-eval-print loop or TREPL):

First, grab a GPU node with qlogin and load the torch module (the torch module also loads cudNN 7.1.3, CUDA 9.0 Toolkit and OpenBLAS):
[abc123@login-0-0 ~]$ qlogin -q gpu.q
[abc123@gpu01 ~]$ module load torch
$ th
 
  ______             __   |  Torch7                                   
 /_  __/__  ________/ /   |  Scientific computing for Lua.         
  / / / _ \/ __/ __/ _ \  |                                           
 /_/  \___/_/  \__/_//_/  |  https://github.com/torch   
                          |  http://torch.ch            
			  
th> torch.Tensor{1,2,3}
 1
 2
 3
[torch.DoubleTensor of dimension 3]

th>

To exit the interactive session, type ^c twice — the control key together with the c key, twice, or type os.exit(). Once the user has entered a complete expression, such as 1 + 2, and hits enter, the interactive session evaluates the expression and shows its value.

To evaluate expressions written in a source file file.lua, write dofile "file.lua".

To run code in a file non-interactively, you can give it as the first argument to the th command::

$ th file.lua

There are various ways to run Lua code and provide options, similar to those available for the perl and rubyprograms:

 $ th -h
Usage: th [options] [script.lua [arguments]]

Options:
  -l name            load library name
  -e statement       execute statement
  -h,--help          print this help
  -a,--async         preload async (libuv) and start async repl (BETA)
  -g,--globals       monitor global variables (print a warning on creation/access)
  -gg,--gglobals     monitor global variables (throw an error on creation/access)
  -x,--gfx           start gfx server and load gfx env
  -i,--interactive   enter the REPL after executing a script

-- AdminUser - 04 May 2018
Topic revision: r1 - 04 May 2018, AdminUser
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback