Automatic differentiation with weighted finite-state transducers.

Related tags

Deep Learning gtn
Overview
logo

GTN: Automatic Differentiation with WFSTs

Quickstart | Installation | Documentation

facebookresearch Documentation Status

What is GTN?

GTN is a framework for automatic differentiation with weighted finite-state transducers. The framework is written in C++ and has bindings to Python.

The goal of GTN is to make adding and experimenting with structure in learning algorithms much simpler. This structure is encoded as weighted automata, either acceptors (WFSAs) or transducers (WFSTs). With gtn you can dynamically construct complex graphs from operations on simpler graphs. Automatic differentiation gives gradients with respect to any input or intermediate graph with a single call to gtn.backward.

Also checkout the repository gtn_applications which consists of GTN applications to Handwriting Recognition (HWR), Automatic Speech Recognition (ASR) etc.

Quickstart

First install the python bindings.

The following is a minimal example of building two WFSAs with gtn, constructing a simple function on the graphs, and computing gradients. Open In Colab

import gtn

# Make some graphs:
g1 = gtn.Graph()
g1.add_node(True)  # Add a start node
g1.add_node()  # Add an internal node
g1.add_node(False, True)  # Add an accepting node

# Add arcs with (src node, dst node, label):
g1.add_arc(0, 1, 1)
g1.add_arc(0, 1, 2)
g1.add_arc(1, 2, 1)
g1.add_arc(1, 2, 0)

g2 = gtn.Graph()
g2.add_node(True, True)
g2.add_arc(0, 0, 1)
g2.add_arc(0, 0, 0)

# Compute a function of the graphs:
intersection = gtn.intersect(g1, g2)
score = gtn.forward_score(intersection)

# Visualize the intersected graph:
gtn.draw(intersection, "intersection.pdf")

# Backprop:
gtn.backward(score)

# Print gradients of arc weights 
print(g1.grad().weights_to_list()) # [1.0, 0.0, 1.0, 0.0]

Installation

Requirements

  • A C++ compiler with good C++14 support (e.g. g++ >= 5)
  • cmake >= 3.5.1, and make

Python

Install the Python bindings with

pip install gtn

Building C++ from source

First, clone the project:

git clone [email protected]:facebookresearch/gtn.git && cd gtn

Create a build directory and run CMake and make:

mkdir -p build && cd build
cmake ..
make -j $(nproc)

Run tests with:

make test

Run make install to install.

Python bindings from source

Setting up your environment:

conda create -n gtn_env
conda activate gtn_env

Required dependencies:

cd bindings/python
conda install setuptools

Use one of the following commands for installation:

python setup.py install

or, to install in editable mode (for dev):

python setup.py develop

Python binding tests can be run with make test, or with

python -m unittest discover bindings/python/test

Run a simple example:

python bindings/python/examples/simple_graph.py

Citing this Repository

If you use the code in this repository, please cite:

Awni Hannun, Vineel Pratap, Jacob Kahn and Wei-Ning Hsu. Differentiable Weighted Finite-State Transducers. arXiv 2010.01003, 2020.

@article{hannun2020dwfst,
  title={Differentiable Weighted Finite-State Transducers},
  author={Hannun, Awni and Pratap, Vineel and Kahn, Jacob and Hsu, Wei-Ning},
  journal={arXiv preprint arXiv:2010.01003},
  year={2020}
}

License

GTN is licensed under a MIT license. See LICENSE.

Comments
  • ImportError: GLIBCXX_3.4.29 not found required by .....

    ImportError: GLIBCXX_3.4.29 not found required by .....

    After doing import gtn I get the following import error:

    File "<stdin>", line 1, in <module>
    
      File "/home/meow/.local/lib/python3.9/site-packages/gtn/__init__.py", line 13, in <module>
        from ._graph import *
    ImportError: /home/meow/miniconda3/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /home/meow/.local/lib/python3.9/site-packages/gtn/_graph.cpython-39-x86_64-linux-gnu.so)
    
    opened by Agrover112 10
  • Compilation error and pip install error

    Compilation error and pip install error

    Hi,

    I'm failing the installation in both approaches. I have g++ version 7.5.0 and CMake version 3.23.0

    pip install gtn gives:

    Collecting gtn
      Using cached gtn-0.0.1.tar.gz (14 kB)
    Building wheels for collected packages: gtn
      Building wheel for gtn (setup.py) ... error
      ERROR: Command errored out with exit status 1:
       command: /home/pyp/miniconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p97r2dzi/gtn/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p97r2dzi/gtn/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-7wzo73o6
           cwd: /tmp/pip-install-p97r2dzi/gtn/
      Complete output (49 lines):
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-3.8
      creating build/lib.linux-x86_64-3.8/gtn
      copying src/bindings/python/gtn/__init__.py -> build/lib.linux-x86_64-3.8/gtn
      creating build/lib.linux-x86_64-3.8/gtn/criterion
      copying src/bindings/python/gtn/criterion/__init__.py -> build/lib.linux-x86_64-3.8/gtn/criterion
      running build_ext
      CMake Warning:
        Ignoring extra path from command line:
      
         "/tmp/pip-install-p97r2dzi/gtn/src"
      
      
      CMake Error: The source directory "/tmp/pip-install-p97r2dzi/gtn/src" does not appear to contain CMakeLists.txt.
      Specify --help for usage, or press the help button on the CMake GUI.
      Traceback (most recent call last):
        File "<string>", line 1, in <module>
        File "/tmp/pip-install-p97r2dzi/gtn/setup.py", line 100, in <module>
          setup(
        File "/home/pyp/miniconda3/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
          return distutils.core.setup(**attrs)
        File "/home/pyp/miniconda3/lib/python3.8/distutils/core.py", line 148, in setup
          dist.run_commands()
        File "/home/pyp/miniconda3/lib/python3.8/distutils/dist.py", line 966, in run_commands
          self.run_command(cmd)
        File "/home/pyp/miniconda3/lib/python3.8/distutils/dist.py", line 985, in run_command
          cmd_obj.run()
        File "/home/pyp/miniconda3/lib/python3.8/site-packages/wheel/bdist_wheel.py", line 290, in run
          self.run_command('build')
        File "/home/pyp/miniconda3/lib/python3.8/distutils/cmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "/home/pyp/miniconda3/lib/python3.8/distutils/dist.py", line 985, in run_command
          cmd_obj.run()
        File "/home/pyp/miniconda3/lib/python3.8/distutils/command/build.py", line 135, in run
          self.run_command(cmd_name)
        File "/home/pyp/miniconda3/lib/python3.8/distutils/cmd.py", line 313, in run_command
          self.distribution.run_command(command)
        File "/home/pyp/miniconda3/lib/python3.8/distutils/dist.py", line 985, in run_command
          cmd_obj.run()
        File "/tmp/pip-install-p97r2dzi/gtn/setup.py", line 53, in run
          self.build_extension(ext)
        File "/tmp/pip-install-p97r2dzi/gtn/setup.py", line 92, in build_extension
          subprocess.check_call(
        File "/home/pyp/miniconda3/lib/python3.8/subprocess.py", line 364, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-install-p97r2dzi/gtn/src', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-p97r2dzi/gtn/build/lib.linux-x86_64-3.8/gtn/', '-DPYTHON_EXECUTABLE=/home/pyp/miniconda3/bin/python', '-DPROJECT_SOURCE_DIR=/tmp/pip-install-p97r2dzi/gtn/src', '-DGTN_BUILD_PYTHON_BINDINGS=ON', '-DGTN_BUILD_EXAMPLES=OFF', '-DGTN_BUILD_BENCHMARKS=OFF', '-DGTN_BUILD_TESTS=OFF', '-DCMAKE_BUILD_TYPE=Release']' returned non-zero exit status 1.
      ----------------------------------------
      ERROR: Failed building wheel for gtn
      Running setup.py clean for gtn
    Failed to build gtn
    Installing collected packages: gtn
        Running setup.py install for gtn ... error
        ERROR: Command errored out with exit status 1:
         command: /home/pyp/miniconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p97r2dzi/gtn/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p97r2dzi/gtn/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-3jz66vin/install-record.txt --single-version-externally-managed --compile --install-headers /home/pyp/miniconda3/include/python3.8/gtn
             cwd: /tmp/pip-install-p97r2dzi/gtn/
        Complete output (51 lines):
        running install
        running build
        running build_py
        creating build
        creating build/lib.linux-x86_64-3.8
        creating build/lib.linux-x86_64-3.8/gtn
        copying src/bindings/python/gtn/__init__.py -> build/lib.linux-x86_64-3.8/gtn
        creating build/lib.linux-x86_64-3.8/gtn/criterion
        copying src/bindings/python/gtn/criterion/__init__.py -> build/lib.linux-x86_64-3.8/gtn/criterion
        running build_ext
        CMake Warning:
          Ignoring extra path from command line:
        
           "/tmp/pip-install-p97r2dzi/gtn/src"
        
        
        CMake Error: The source directory "/tmp/pip-install-p97r2dzi/gtn/src" does not appear to contain CMakeLists.txt.
        Specify --help for usage, or press the help button on the CMake GUI.
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/tmp/pip-install-p97r2dzi/gtn/setup.py", line 100, in <module>
            setup(
          File "/home/pyp/miniconda3/lib/python3.8/site-packages/setuptools/__init__.py", line 153, in setup
            return distutils.core.setup(**attrs)
          File "/home/pyp/miniconda3/lib/python3.8/distutils/core.py", line 148, in setup
            dist.run_commands()
          File "/home/pyp/miniconda3/lib/python3.8/distutils/dist.py", line 966, in run_commands
            self.run_command(cmd)
          File "/home/pyp/miniconda3/lib/python3.8/distutils/dist.py", line 985, in run_command
            cmd_obj.run()
          File "/home/pyp/miniconda3/lib/python3.8/site-packages/setuptools/command/install.py", line 61, in run
            return orig.install.run(self)
          File "/home/pyp/miniconda3/lib/python3.8/distutils/command/install.py", line 545, in run
            self.run_command('build')
          File "/home/pyp/miniconda3/lib/python3.8/distutils/cmd.py", line 313, in run_command
            self.distribution.run_command(command)
          File "/home/pyp/miniconda3/lib/python3.8/distutils/dist.py", line 985, in run_command
            cmd_obj.run()
          File "/home/pyp/miniconda3/lib/python3.8/distutils/command/build.py", line 135, in run
            self.run_command(cmd_name)
          File "/home/pyp/miniconda3/lib/python3.8/distutils/cmd.py", line 313, in run_command
            self.distribution.run_command(command)
          File "/home/pyp/miniconda3/lib/python3.8/distutils/dist.py", line 985, in run_command
            cmd_obj.run()
          File "/tmp/pip-install-p97r2dzi/gtn/setup.py", line 53, in run
            self.build_extension(ext)
          File "/tmp/pip-install-p97r2dzi/gtn/setup.py", line 92, in build_extension
            subprocess.check_call(
          File "/home/pyp/miniconda3/lib/python3.8/subprocess.py", line 364, in check_call
            raise CalledProcessError(retcode, cmd)
        subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-install-p97r2dzi/gtn/src', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-p97r2dzi/gtn/build/lib.linux-x86_64-3.8/gtn/', '-DPYTHON_EXECUTABLE=/home/pyp/miniconda3/bin/python', '-DPROJECT_SOURCE_DIR=/tmp/pip-install-p97r2dzi/gtn/src', '-DGTN_BUILD_PYTHON_BINDINGS=ON', '-DGTN_BUILD_EXAMPLES=OFF', '-DGTN_BUILD_BENCHMARKS=OFF', '-DGTN_BUILD_TESTS=OFF', '-DCMAKE_BUILD_TYPE=Release']' returned non-zero exit status 1.
        ----------------------------------------
    ERROR: Command errored out with exit status 1: /home/pyp/miniconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-p97r2dzi/gtn/setup.py'"'"'; __file__='"'"'/tmp/pip-install-p97r2dzi/gtn/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-3jz66vin/install-record.txt --single-version-externally-managed --compile --install-headers /home/pyp/miniconda3/include/python3.8/gtn Check the logs for full command output.
    

    When build from source, running make -j 8 gives:

    [  1%] Building CXX object CMakeFiles/gtn.dir/gtn/autograd.cpp.o
    [  3%] Building CXX object CMakeFiles/gtn.dir/gtn/cpu/creations.cpp.o
    [  5%] Building CXX object CMakeFiles/gtn.dir/gtn/cpu/compose.cpp.o
    [  6%] Building CXX object CMakeFiles/gtn.dir/gtn/cpu/functions.cpp.o
    [  8%] Building CXX object CMakeFiles/gtn.dir/gtn/cpu/shortest.cpp.o
    [ 10%] Building CXX object CMakeFiles/gtn.dir/gtn/creations.cpp.o
    [ 11%] Building CXX object CMakeFiles/gtn.dir/gtn/device.cpp.o
    [ 13%] Building CXX object CMakeFiles/gtn.dir/gtn/criterions.cpp.o
    [ 15%] Building CXX object CMakeFiles/gtn.dir/gtn/functions.cpp.o
    [ 16%] Building CXX object CMakeFiles/gtn.dir/gtn/graph.cpp.o
    [ 18%] Building CXX object CMakeFiles/gtn.dir/gtn/parallel/parallel_map.cpp.o
    [ 20%] Building CXX object CMakeFiles/gtn.dir/gtn/rand.cpp.o
    [ 22%] Building CXX object CMakeFiles/gtn.dir/gtn/utils.cpp.o
    [ 23%] Building CUDA object CMakeFiles/gtn.dir/gtn/cuda/creations.cu.o
    [ 25%] Building CUDA object CMakeFiles/gtn.dir/gtn/cuda/compose.cu.o
    [ 27%] Building CUDA object CMakeFiles/gtn.dir/gtn/cuda/cuda.cu.o
    [ 28%] Building CXX object CMakeFiles/gtn.dir/gtn/cuda/functions.cpp.o
    [ 30%] Building CUDA object CMakeFiles/gtn.dir/gtn/cuda/shortest.cu.o
    /home/pyp/gtn/gtn/cuda/cuda.cu(94): error: identifier "cudaMallocAsync" is undefined
    
    /home/pyp/gtn/gtn/cuda/cuda.cu(99): error: identifier "cudaFreeAsync" is undefined
    
    /home/pyp/gtn/gtn/cuda/shortest.cu(19): error: A __constant__ variable cannot be marked constexpr
    
    /home/pyp/gtn/gtn/cuda/shortest.cu(20): error: A __constant__ variable cannot be marked constexpr
    
    2 errors detected in the compilation of "/home/pyp/gtn/gtn/cuda/cuda.cu".
    CMakeFiles/gtn.dir/build.make:285: recipe for target 'CMakeFiles/gtn.dir/gtn/cuda/cuda.cu.o' failed
    make[2]: *** [CMakeFiles/gtn.dir/gtn/cuda/cuda.cu.o] Error 1
    make[2]: *** Waiting for unfinished jobs....
    2 errors detected in the compilation of "/home/pyp/gtn/gtn/cuda/shortest.cu".
    CMakeFiles/gtn.dir/build.make:313: recipe for target 'CMakeFiles/gtn.dir/gtn/cuda/shortest.cu.o' failed
    make[2]: *** [CMakeFiles/gtn.dir/gtn/cuda/shortest.cu.o] Error 1
    CMakeFiles/Makefile2:173: recipe for target 'CMakeFiles/gtn.dir/all' failed
    make[1]: *** [CMakeFiles/gtn.dir/all] Error 2
    Makefile:145: recipe for target 'all' failed
    make: *** [all] Error 2
    

    Thank you so much for your time!

    opened by jasonppy 8
  • Avoiding forward_score underflow for large graphs

    Avoiding forward_score underflow for large graphs

    Hi @awni,

    I encountered some scenarios where the forward_score of a graph that is too large underflows. I'm wondering whether there's a way to work in a higher precision in GTN or whether I should change my methods to avoid such scenarios.

    I reproduced one example here: https://colab.research.google.com/drive/1lRkhxJrPG4tBiHTbASl1iJX84Ao8JU8m?usp=sharing

    g_emissions here comes from a CTC model, but instead of the normal g_criterion I use a modified version which marginalizes over many subword decompositions (similar to 4.2 in your paper https://arxiv.org/pdf/2010.01003.pdf). This is why my graphs are so large - do you have any suggestions?

    opened by brianyan918 4
  • Parallel compose only works sequentially

    Parallel compose only works sequentially

    I tried to implement a simple parallelFor using the underlying threadpool.

    template <typename FuncType>
    auto parallelFor(FuncType&& function, size_t size) {
      // Skipping bits similar to parallelMap
      ...
      for (size_t i = 0; i < size; ++i) {
        futures[i] = threadPool.get().enqueue(
          [size, i, &function, &eMutex, &eQueue]() -> OutType {
            try {
              return function(i);
            } catch (...) {
              .....
            }
          }
        );
      }
      ....
      }
      return out.value();
    }
    

    When using this method to perform the various for loops which according to the comments, should be independent on the iteration, I found that the code tends to fail. So far, my guess as to the source of the error is in the computeNodeAndArcPair function, although not sure.

    An easy way to reproduce this error is to reverse the order in which the arcs are being processed. For instance on line 668

        for (int tid = totalArcs - 1; tid > 0; --tid) {
    

    Again the same on line 491 and line 372

    opened by ptigwe 3
  • Compilation error with CUDA

    Compilation error with CUDA

    I am trying to compile GTN with CUDA support. I am using CUDA 11.2 and gcc 9.4.0.

    I ran: cmake -DCMAKE_CUDA_COMPILER=/usr/local/cuda/11.2/bin/nvcc -DCMAKE_CUDA_ARCHITECTURES=80 .. which succeeds.

    However, cmake -j 8 results in:

    $ make -j 8
    
    Scanning dependencies of target gtn
    [  5%] Building CXX object CMakeFiles/gtn.dir/gtn/creations.cpp.o
    [  6%] Building CXX object CMakeFiles/gtn.dir/gtn/device.cpp.o
    [ 11%] Building CXX object CMakeFiles/gtn.dir/gtn/cpu/shortest.cpp.o
    [  3%] Building CXX object CMakeFiles/gtn.dir/gtn/cpu/creations.cpp.o
    [ 13%] Building CXX object CMakeFiles/gtn.dir/gtn/cpu/compose.cpp.o
    [ 13%] Building CXX object CMakeFiles/gtn.dir/gtn/cpu/functions.cpp.o
    [ 13%] Building CXX object CMakeFiles/gtn.dir/gtn/autograd.cpp.o
    [ 13%] Building CXX object CMakeFiles/gtn.dir/gtn/criterions.cpp.o
    [ 15%] Building CXX object CMakeFiles/gtn.dir/gtn/functions.cpp.o
    [ 16%] Building CXX object CMakeFiles/gtn.dir/gtn/graph.cpp.o
    [ 18%] Building CXX object CMakeFiles/gtn.dir/gtn/parallel/parallel_map.cpp.o
    [ 20%] Building CXX object CMakeFiles/gtn.dir/gtn/rand.cpp.o
    [ 22%] Building CXX object CMakeFiles/gtn.dir/gtn/utils.cpp.o
    [ 23%] Building CUDA object CMakeFiles/gtn.dir/gtn/cuda/creations.cu.o
    [ 25%] Building CUDA object CMakeFiles/gtn.dir/gtn/cuda/compose.cu.o
    [ 27%] Building CUDA object CMakeFiles/gtn.dir/gtn/cuda/cuda.cu.o
    [ 28%] Building CXX object CMakeFiles/gtn.dir/gtn/cuda/functions.cpp.o
    [ 30%] Building CUDA object CMakeFiles/gtn.dir/gtn/cuda/shortest.cu.o
    /gpfs/mariana/home/tanel.alumae/tools/gtn/gtn/cuda/shortest.cu(19): error: A __constant__ variable cannot be marked constexpr
    
    /gpfs/mariana/home/tanel.alumae/tools/gtn/gtn/cuda/shortest.cu(20): error: A __constant__ variable cannot be marked constexpr
    
    2 errors detected in the compilation of "/gpfs/mariana/home/tanel.alumae/tools/gtn/gtn/cuda/shortest.cu".
    make[2]: *** [CMakeFiles/gtn.dir/build.make:303: CMakeFiles/gtn.dir/gtn/cuda/shortest.cu.o] Error 1
    make[2]: *** Waiting for unfinished jobs....
    make[1]: *** [CMakeFiles/Makefile2:198: CMakeFiles/gtn.dir/all] Error 2
    make: *** [Makefile:160: all] Error 2
    

    Any ideas?

    opened by alumae 1
  • CTC Benchmarking code

    CTC Benchmarking code

    Compare CTC performance with torch. Default values in the script correspond to a LibriSpeech example with stride 8 AM and batchsize=32 and 10k Word Pieces.

    Here are some initial numbers (on Nvidia P100)

    python bindings/python/benchmarks/ctc.py -N 10

    Screen Shot 2021-12-28 at 1 37 34 PM
    opened by vineelpratap 1
  • Simplify cmake for experimental directory

    Simplify cmake for experimental directory

    | Summary:

    • CUDA linking made simpler
    • Keep parallel_compose_test.cpp in test/experimental folder

    | Test Plan:

    cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=~/bin/ && make -j80 install make test

    Also, was able to link gtn to a new repossity using cmake .. -Dgtn_DIR=~/bin/share/gtn/cmake/

    opened by vineelpratap 1
  • Speedups to CPU shortest distance / shortest path

    Speedups to CPU shortest distance / shortest path

    TImings on my laptop using ./benchmarks/benchmark_functions

    After Timing forwardScoreLinearForward (cpu) ... 9.1351 msec Timing forwardScoreLinearBackward (cpu) ... 9.085 msec Timing forwardScoreRandDAGForward (cpu) ... 5.7167 msec Timing forwardScoreRandDAGBackward (cpu) ... 6.4635 msec Timing viterbiPathLinearForward (cpu) ... 1.7872 msec Timing viterbiPathLinearBackward (cpu) ... 1.7198 msec Timing viterbiPathRandDAGForward (cpu) ... 2.0626 msec Timing viterbiPathRandDAGBackward (cpu) ... 0.1356 msec

    Before Timing forwardScoreLinearForward (cpu) ... 14.57 msec Timing forwardScoreLinearBackward (cpu) ... 16.383 msec Timing forwardScoreRandDAGForward (cpu) ... 5.8892 msec Timing forwardScoreRandDAGBackward (cpu) ... 11.59 msec Timing viterbiPathLinearForward (cpu) ... 4.2249 msec Timing viterbiPathLinearBackward (cpu) ... 1.7191 msec Timing viterbiPathRandDAGForward (cpu) ... 1.7667 msec Timing viterbiPathRandDAGBackward (cpu) ... 0.087886 msec

    opened by awni 0
  • Some more CUDA functionality

    Some more CUDA functionality

    1. Some optimizations for the CPU SOA data structure
    • Use a pointer for the arc indices instead of making a vector
    • Speed up linear construction
    • Speed up clone
    1. CUDA functionality:
    • Graph::item
    • clone, projectInput, projectOutput
    • equal
    • linearCreation, scalarCreation
    1. Added a Device class to make device management cleaner (very similar to torch.device).

    2. Refactored cpp testing to use a single main. Speeds up build and makes it easy to run all the tests.

    opened by awni 0
  • Fix epsilon composition

    Fix epsilon composition

    Fix bug with epsilon composition.

    Tests

    Running tests... Test project /Users/awni/repos/gtn/build Start 1: autograd_test 1/8 Test #1: autograd_test .................... Passed 0.87 sec Start 2: creations_test 2/8 Test #2: creations_test ................... Passed 0.37 sec Start 3: criterion_test 3/8 Test #3: criterion_test ................... Passed 0.57 sec Start 4: functions_test 4/8 Test #4: functions_test ................... Passed 0.86 sec Start 5: parallel_test 5/8 Test #5: parallel_test .................... Passed 0.81 sec Start 6: graph_test 6/8 Test #6: graph_test ....................... Passed 0.44 sec Start 7: utils_test 7/8 Test #7: utils_test ....................... Passed 0.33 sec Start 8: rand_test 8/8 Test #8: rand_test ........................ Passed 0.50 sec

    100% tests passed, 0 tests failed out of 8

    Total Test time (real) = 4.74 sec

    Benchmarks

    TLDR not a huge impact, negligible for CTC.

    Before fix

    Timing composeForward ... 142.12 msec Timing composeBackward ... 0.79 msec Timing composeForwardSorted ... 9.53 msec Timing ctcLoss ... 124.37 msec Timing ctcGrad ... 21.44 msec Timing ngramCtcLoss ... 5.47 msec Timing ngramCtcGrad ... 0.61 msec Timing ctcBatched ... 210.01 msec

    After fix

    Timing composeForward ... 144.14 msec Timing composeBackward ... 0.8 msec Timing composeForwardSorted ... 10.19 msec Timing ctcLoss ... 131.27 msec Timing ctcGrad ... 21.73 msec Timing ngramCtcLoss ... 6.19 msec Timing ngramCtcGrad ... 0.61 msec Timing ctcBatched ... 218.7 msec

    opened by awni 0
  • Added use of chain rule in pytorch examples.

    Added use of chain rule in pytorch examples.

    Hi! I noticed that the python example and docs for interfacing with pytorch didn't make use of the chain rule, which led to wrong gradients when you do things downstream with the loss.

    opened by namednil 0
  • Add explicit Python dependencies used in tests (torch, numpy etc.)

    Add explicit Python dependencies used in tests (torch, numpy etc.)

    Hi and thanks for a great library!

    I noticed some of the README and examples import several Python libraries (e.g. numpy, torch etc.) that aren't listed anywhere as explicit dependencies. I feel like this could be helpful so that users can run the tests directly after installing the Python bindings:

    python -m unittest discover bindings/python/test
    

    Alternatively, the README could also instruct the user to install these manually, but that's a bit more hassle.

    Happy to submit a PR for this. :-)

    opened by j0ma 0
  • Python test failed

    Python test failed

    Hi,

    Since I couldn't get gtn to compile with cuda (see our conversation in this issue), I turned off all CUDA related options. Specifically, I changed https://github.com/gtn-org/gtn/blob/master/CMakeLists.txt#L17 to OFF, and deleted https://github.com/gtn-org/gtn/blob/master/bindings/python/CMakeLists.txt#L28.

    With the above changes, running

    mkdir -p build && cd build
    cmake ..
    make -j $(nproc)
    

    were successful

    and running

    cd bindings/python
    conda install setuptools
    python setup.py develop
    

    were also successful,

    However, when running

    python -m unittest discover bindings/python/test
    

    I also commented https://github.com/gtn-org/gtn/blob/master/bindings/python/gtn/init.py#L21, and delete ./bindings/python/test/test_cuda.py

    I got output:

    ...F................................F...........
    ======================================================================
    FAIL: test_forward_score_grad (test_autograd.AutogradTestCase)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/pyp/gtn/bindings/python/test/test_autograd.py", line 261, in test_forward_score_grad
        self.assertTrue(math.isnan(grad_weights[0]))
    AssertionError: False is not true
    
    ======================================================================
    FAIL: test_forward (test_functions.FunctionsTestCase)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/pyp/gtn/bindings/python/test/test_functions.py", line 217, in test_forward
        self.assertRaises(ValueError, gtn.forward_score, g)
    AssertionError: ValueError not raised by forward_score
    
    ----------------------------------------------------------------------
    Ran 48 tests in 0.158s
    
    FAILED (failures=2)
    

    Thanks for your time!

    opened by jasonppy 2
  • Check for ambiguity?

    Check for ambiguity?

    Hi! First of all, I think this is a cool project!

    I was wondering if you have considered adding an optional parameter to forwardScore that invokes a check if the FSA/FST is unambiguous (i.e. at most one run per word)? If the FSA is ambiguous then the forward algorithm will fail to compute the weight of the language because some words are counted multiple times. I'm not sure if this is desired in some cases but I think there should be a way to get a warning at least.

    opened by namednil 0
Owner
null
This tool converts a Nondeterministic Finite Automata (NFA) into a Deterministic Finite Automata (DFA)

This tool converts a Nondeterministic Finite Automata (NFA) into a Deterministic Finite Automata (DFA)

Quinn Herden 1 Feb 4, 2022
Automatic Differentiation Multipole Moment Molecular Forcefield

Automatic Differentiation Multipole Moment Molecular Forcefield Performance notes On a single gpu, using waterbox_31ang.pdb example from MPIDplugin wh

null 4 Jan 7, 2022
Aircraft design optimization made fast through modern automatic differentiation

Aircraft design optimization made fast through modern automatic differentiation. Plug-and-play analysis tools for aerodynamics, propulsion, structures, trajectory design, and much more.

Peter Sharpe 394 Dec 23, 2022
Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It can use GPUs and perform efficient symbolic differentiation.

============================================================================================================ `MILA will stop developing Theano <https:

null 9.6k Dec 31, 2022
Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It can use GPUs and perform efficient symbolic differentiation.

============================================================================================================ `MILA will stop developing Theano <https:

null 9.6k Jan 6, 2023
Theano is a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays efficiently. It can use GPUs and perform efficient symbolic differentiation.

============================================================================================================ `MILA will stop developing Theano <https:

null 9.3k Feb 12, 2021
JAX code for the paper "Control-Oriented Model-Based Reinforcement Learning with Implicit Differentiation"

Optimal Model Design for Reinforcement Learning This repository contains JAX code for the paper Control-Oriented Model-Based Reinforcement Learning wi

Evgenii Nikishin 43 Sep 28, 2022
ShapeGlot: Learning Language for Shape Differentiation

ShapeGlot: Learning Language for Shape Differentiation Created by Panos Achlioptas, Judy Fan, Robert X.D. Hawkins, Noah D. Goodman, Leonidas J. Guibas

Panos 32 Dec 23, 2022
Automatic Calibration for Non-repetitive Scanning Solid-State LiDAR and Camera Systems

ACSC Automatic extrinsic calibration for non-repetitive scanning solid-state LiDAR and camera systems. System Architecture 1. Dependency Tested with U

KINO 192 Dec 13, 2022
Finite-temperature variational Monte Carlo calculation of uniform electron gas using neural canonical transformation.

CoulombGas This code implements the neural canonical transformation approach to the thermodynamic properties of uniform electron gas. Building on JAX,

FermiFlow 9 Mar 3, 2022
Finite difference solution of 2D Poisson equation. Can handle Dirichlet, Neumann and mixed boundary conditions.

Poisson-solver-2D Finite difference solution of 2D Poisson equation Current version can handle Dirichlet, Neumann, and mixed (combination of Dirichlet

Mohammad Asif Zaman 34 Dec 23, 2022
Finite Element Analysis

FElupe - Finite Element Analysis FElupe is a Python 3.6+ finite element analysis package focussing on the formulation and numerical solution of nonlin

Andreas D. 20 Jan 9, 2023
Using NumPy to solve the equations of fluid mechanics together with Finite Differences, explicit time stepping and Chorin's Projection methods

Computational Fluid Dynamics in Python Using NumPy to solve the equations of fluid mechanics ?? ?? ?? together with Finite Differences, explicit time

Felix Köhler 4 Nov 12, 2022
Automatic self-diagnosis program (python required)Automatic self-diagnosis program (python required)

auto-self-checker 자동으로 자가진단 해주는 프로그램(python 필요) 중요 이 프로그램이 실행될때에는 절대로 마우스포인터를 움직이거나 키보드를 건드리면 안된다(화면인식, 마우스포인터로 직접 클릭) 사용법 프로그램을 구동할 폴더 내의 cmd창에서 pip

null 1 Dec 30, 2021
Monocular Depth Estimation - Weighted-average prediction from multiple pre-trained depth estimation models

merged_depth runs (1) AdaBins, (2) DiverseDepth, (3) MiDaS, (4) SGDepth, and (5) Monodepth2, and calculates a weighted-average per-pixel absolute dept

Pranav 39 Nov 21, 2022
Code for paper: Group-CAM: Group Score-Weighted Visual Explanations for Deep Convolutional Networks

Group-CAM By Zhang, Qinglong and Rao, Lu and Yang, Yubin [State Key Laboratory for Novel Software Technology at Nanjing University] This repo is the o

zhql 98 Nov 16, 2022
Weighted QMIX: Expanding Monotonic Value Function Factorisation

This repo contains the cleaned-up code that was used in "Weighted QMIX: Expanding Monotonic Value Function Factorisation"

whirl 82 Dec 29, 2022
Implements an infinite sum of poisson-weighted convolutions

An infinite sum of Poisson-weighted convolutions Kyle Cranmer, Aug 2018 If viewing on GitHub, this looks better with nbviewer: click here Consider a v

Kyle Cranmer 26 Dec 7, 2022