はじめに
本記事はPytorchのRustバインディングをUbuntu版VisualStudioCode上で試してみました。
真っ更な状態のUbuntuからRustバインディングを実行する方法までを初学者向けに極力丁寧に書いています。
対象者
PythonからRustに乗り換えたいなーと考えているRust初学者
環境情報
バージョン備考Ubuntu20.04.3 LTS
Rustc1.56.1Rustコンパイラ
※下記Rustインストール手順にて自動的にインストールされるRustup1.24.3Rustインストーラおよびバージョン管理ツール
※下記Rustインストール手順にて自動的にインストールされるCargo1.56.0Rustビルドツール
※下記Rustインストール手順にて自動的にインストールされるVisualStudioCode1.62.3
Rust support for VisualStudioCode0.7.8VSCode拡張機能RustツールCodeLLDB1.6.10VSCode拡張機能Rustデバッガー
Rustc1.56.1Rustコンパイラ
※下記Rustインストール手順にて自動的にインストールされるRustup1.24.3Rustインストーラおよびバージョン管理ツール
※下記Rustインストール手順にて自動的にインストールされるCargo1.56.0Rustビルドツール
※下記Rustインストール手順にて自動的にインストールされるVisualStudioCode1.62.3
Rust support for VisualStudioCode0.7.8VSCode拡張機能RustツールCodeLLDB1.6.10VSCode拡張機能Rustデバッガー
Pytorch/Rustバインディング
今回実行するPytorch/Rustバインディングはこちら
tch-rs
Rust実行環境を構築する
Rustをインストールする

Rustがインストールされたか確認するために下記コマンドをする
rustc -V
rustup -V
cargo --version
VisualStudioCodeをインストールする

VisualStudioCodeの拡張機能をインストールする

GitリポジトリのクローンおよびMNISTのダウンロードを行う





CodeLLDBの設定を行う



{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug example 'mnist'",
"cargo": {
"args": [
"build",
"--example=mnist",
"--package=tch"
],
"filter": {
"name": "mnist",
"kind": "example"
}
},
"args": [],
"cwd": "${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug unit tests in example 'mnist'",
"cargo": {
"args": [
"test",
"--no-run",
"--example=mnist",
"--package=tch"
],
"filter": {
"name": "mnist",
"kind": "example"
}
},
"args": [],
"cwd": "${workspaceFolder}"
}
]
}

Pytorch/Rustバインディングを実行する


実行結果

以上です