Kaldi on AWS
đ Hi, itâs Josh here. Iâm writing you this note in 2021: the world of speech technology has changed dramatically since Kaldi. Before devoting weeks of your time to deploying Kaldi, take a look at đ¸ Coqui Speech-to-Text. It takes minutes to deploy an off-the-shelf đ¸ STT model, and itâs open source on Github. Iâm on the Coqui founding team so Iâm admittedly biased. However, you can tell from this blog that Iâve spent years working with Kaldi, so I understand the headaches.
With đ¸ STT, weâve removed the headaches of Kaldi and streamlined everything for production settings. You can train and deploy state-of-the-art đ¸ Speech-to-Text models in just minutes, not weeks. Check out the đ¸ Model Zoo for open, pre-trained models in different languages. Try it out for yourself, and come join our friendly chatroom đ
General Notes
- Nice intro to Amazonâs EC2 services
- Use
tmux
: nice for running a model in background after exitingssh
- Install
emacs
orvim
: youâre going to need some kind of text editor which works well in the terminal. - Installing Kaldi on
t2.micro
will run out of RAM and crash, so youâre going to have to pay.
Set up Instance
Choose Instance
You can only launch instances which you have permissions for, find the list of available instances here:
Instance Info
https://aws.amazon.com/ec2/instance-types/
Instance Pricing
https://aws.amazon.com/ec2/pricing/on-demand/
My Set-up
Iâve been working on the following set-up, so it should work for you as well.
- operating system:
Ubuntu Server 16.04 LTS
- instance type:
g2.2xlarge
The instance type Iâm using is for GPUs, which is probably what you want⌠especially if youâre using nnet3
. Itâs more expensive than using a CPU, but if youâre running lots of data or experiments, you will want GPUs. Each iteration in DNN training takes a lot less time on a GPU.
If you really want to use a CPU system, Iâd recommend c4.xlarge
. Actually, if youâre only running GMMs, then more CPUs is better than a single GPU, since GMMs donât train on GPUs, and itâs easier to parallelize GMMs so you get more bang for your buck with a bunch of CPUs.
Donât forget: a standard, compiled Kaldi will take up to 15 gigs
of disk space, so make sure you allocate it on the instance when youâre setting it up (on the Storage
step). This is why you should also really use ./configure --shared
below, it will shave off some gigs.
Download Key Pair
Generate a key-pair, and make it secure with chmod
(this is a necessary step).
Donât lose this file, or you wonât be able to get back into your instance!
SSH into instance
Now use your key-pair and ssh
into your instance.
Update and Upgrade Ubuntu
This is necessary to install Kaldi successfully.
If youâve gotten to this point without any hiccups, you should have a working Ubuntu
installation on your AWS
instance! Now, letâs quickly download and compile Kaldi
on our new instance:)
Install Dependencies
Install CUDA
I got these steps from this good post on askubuntu. If you have issues, that post is more detailed, check it out. Normally, though, these steps should work.
First download CUDA from NVIDIA. You might need a different link here depending on when you read this.
Install CUDA:
Add CUDA to your PATH
variable:
Take a look at your install:
Once youâre training, you can look at GPU usage (like top
for CPUs) like this:
Install Kaldi on Instance
The following is a list of commands, assuming youâve already had experience installing Kaldi. However, if youâre interested, hereâs a thorough walk-through on installing Kaldi.
Clone Kaldi
Compile 3rd Party Tools
Compile Kaldi Source
At this point, if you didnât get any ERROR
messages or major WARNING
s, you should have a working installation of Kaldi
in the cloud!
To make sure youâve go everything working, go ahead and run the simple yesno
demo:
Test it out!
If it runs as normal, youâre good to go:)
Now you can tranfer your own data to your instance and start working. You should probably check out Amazonâs EBS volumes for storing your data, but thatâs another post. Here, Iâm just going to show you how to transfrom data from your local computer to your new instance, and then you should be able to train models as if they were on your machine.
Transfer Data
Transfer Data from Laptop to Instace
You can easily transfer data from your local machine to your new AWS
instance. Open a terminal on your machine and do something like this:
Attach an EBS Volume
This is from what I gather the best way to work with data on AWS for these kinds of applications (machine learning training).
If you have your data on an EBS volume, it is logically separate from your scripts and codebase on EC2 instance. Splitting data and code is good practice, especially if youâre using git and GitHub.
My code for speech recognition experiements is in one git repo, and I can easily spin up an EC2 instance, clone my repo, and use symbolic links to my data on EBS after Iâve mounted it. This way, you can plug and play with different data sets, or code bases.
Also, git will get mad at you iff your files are too big or if your repo is too big. You should really only have text files on git.
- create EBS Volume in same availability zone (not just region!) as your EC2
- put data on EBS Volume
Then you need to:
- stop EC2 instance
- attach EBS to EC2
- mount EBS from within a ssh session on EC2
Train Models
If you want a real walk-through, check out my post on how to train a DNN in Kaldi. The following is more of a cheatsheet than anything.
The Quick and Dirty
ssh -i ~/Desktop/your-key-pair.pem ubuntu@ec2-11-222-33-444.us-west-2.compute.amazonaws.com
- start new terminal session:
tmux new -s my-session
- run model:
KALDI$ ./run.sh
- exit terminal session without terminating:
Ctrl-b d
- get back into terminal session:
tmux a -t my-session
Conclusion
I hope this was helpful!
Let me know if you have comments or suggestions and you can always leave a comment below.
Happy Kaldi-ing!