Skip to content
This repository has been archived by the owner on Dec 26, 2020. It is now read-only.
/ TransformerAPI Public archive

Example API server (using swift-nio) that wraps a Swift for TensorFlow model

Notifications You must be signed in to change notification settings

swaroopch/TransformerAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Transformer API

Background

The idea for this project comes from Brennan Saeta at the try! Swift San Jose 2019 conference.

The project is an example API server wrapping a Swift for TensorFlow model, particularly the Swift for TensorFlow implementation of OpenAI’s GPT-2 Transformer language model.

Prerequisites

NOTE: This project was compiled on Ubuntu 19.04 with the nightly snapshot of Swift for TensorFlow as of [2019-06-06 Thu].

Setup Python + Ensure Swift for TensorFlow models compile

# Build models
mkdir -p ~/code/swift-source
cd ~/code/swift-source
git clone https://github.com/tensorflow/swift-models
cd swift-models
# https://github.com/tensorflow/swift-models/blob/master/README.md#build
swift build -v -Xlinker -ltensorflow

# https://colab.research.google.com/github/tensorflow/swift/blob/master/docs/site/tutorials/python_interoperability.ipynb
export PYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.7m.so.1.0

sudo apt install python3-pip
pip3 install regex numpy

cd Transformer
./main 0.5 "My name is"

Serve API

Terminal 1 : Start server

# Switch to this repo

cd Sources/TransformerAPI/
bash download_model.sh 345M

cd ../..
swift build
swift run TransformerAPI

Terminal 2 : Run client

curl http://localhost:8888/blabber -d "I'm at a conference" && echo    

Example results:

 with the US Congress on climate change, and I'm talking about the Paris Agreement, which is the main signatory to the Copenhagen Accord. And I think it's important to understand that the Paris Agreement is not a treaty, it's a treaty on climate change.

I think it's important to understand that the Paris Agreement is not a treaty on climate change.

The Paris Agreement is not a treaty on climate change.

And I think that's the kind of thing that we

FAQ

Why swift-nio? Why not Vapor or Kitura?

Because both projects were not ready for Swift 5 & Ubuntu 19.04, as of [2019-06-07 Fri]. At least, I couldn’t get them working.

Whereas I was able to get a simple swift-nio based http server, thanks to the example code & help from actual engineers who work at Apple on swift-nio who were present for try! Swift San Jose 2019 :).

About

Example API server (using swift-nio) that wraps a Swift for TensorFlow model

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published