ドキュメント|チュートリアル|ベンチマーク|実装された論文
Torchdrugは、いくつかの目的のために設計されたPytorchベースの機械学習ツールボックスです。
Torchdrugは、Linux、Windows、またはMacOSのいずれかにインストールできます。 3.7 <= python <= 3.10およびpytorch> = 1.8.0と互換性があります。
conda install torchdrug -c milagraph -c conda-forge -c pytorch -c pygpip install torch==1.9.0
pip install torch-scatter torch-cluster -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
pip install torchdrug他のPytorchまたはCudaバージョン用のtorch-scatterをインストールするには、https://github.com/rusty1s/pytorch_scatterの手順をご覧ください
git clone https://github.com/DeepGraphLearning/torchdrug
cd torchdrug
pip install -r requirements.txt
python setup.py installVisual Studio用のビルドツールを最初にインストールする必要があります。次に、PowerShellに次のモジュールをインストールします。
Install-Module Pscx - AllowClobber
Install-Module VSSetupPowershellのVisual Studioを次のコマンドで初期化します。 PowerShellプロファイルに書き込むことにより、すべてのPowerShellセッションに対してこれをセットアップする場合があります。自分のケースに従ってライブラリパスを変更します。
Import-VisualStudioVars - Architecture x64
$ env: LIB += " ;C:Program FilesPython37libs " AppleシリコンでTorchdrugを実行するには、pytorch> = 1.13が必要です。 torch-scatterとtorch-clusterの場合、それらはソースからコンパイルできます。 Torchdrugはmpsデバイスをサポートしていません。
pip install torch==1.13.0
pip install git+https://github.com/rusty1s/pytorch_scatter.git
pip install git+https://github.com/rusty1s/pytorch_cluster.git
pip install torchdrugTorchdrugは人間用に設計されており、グラフ構造データに焦点を当てています。これにより、機械学習モデルでグラフ操作を簡単に実装できます。 Torchdrugのすべての操作は、Pytorchフレームワークに支えられており、GPUの加速と自動分化をサポートしています。
from torchdrug import data
edge_list = [[ 0 , 1 ], [ 1 , 2 ], [ 2 , 3 ], [ 3 , 4 ], [ 4 , 5 ], [ 5 , 0 ]]
graph = data . Graph ( edge_list , num_node = 6 )
graph = graph . cuda ()
# the subgraph induced by nodes 2, 3 & 4
subgraph = graph . subgraph ([ 2 , 3 , 4 ])分子はTorchdrugでもサポートされています。ドメインの知識なしで、目的の分子特性を取得できます。
mol = data . Molecule . from_smiles ( "CCOC(=O)N" , atom_feature = "default" , bond_feature = "default" )
print ( mol . node_feature )
print ( mol . atom_type )
print ( mol . to_scaffold ())また、カスタムノード、エッジ、またはグラフ属性を登録することもできます。インデックス操作中に自動的に処理されます。
with mol . edge ():
mol . is_CC_bond = ( mol . edge_list [:, : 2 ] == td . CARBON ). all ( dim = - 1 )
sub_mol = mol . subgraph ( mol . atom_type != td . NITROGEN )
print ( sub_mol . is_CC_bond )Torchdrugは、幅広い一般的なデータセットと、創薬のためのビルディングブロックを提供します。最小限のコードを使用すると、標準モデルを適用して独自の問題を解決できます。
import torch
from torchdrug import datasets
dataset = datasets . Tox21 ()
dataset [ 0 ]. visualize ()
lengths = [ int ( 0.8 * len ( dataset )), int ( 0.1 * len ( dataset ))]
lengths += [ len ( dataset ) - sum ( lengths )]
train_set , valid_set , test_set = torch . utils . data . random_split ( dataset , lengths ) from torchdrug import models , tasks
model = models . GIN ( dataset . node_feature_dim , hidden_dims = [ 256 , 256 , 256 , 256 ])
task = tasks . PropertyPrediction ( model , task = dataset . tasks )トレーニングと推論は、複数のCPUまたはGPUによって加速されます。これは、単なるコードでTorchdrugでシームレスに切り替えることができます。
from torchdrug import core
# Single CPU / Multiple CPUs / Distributed CPUs
solver = core . Engine ( task , train_set , valid_set , test_set , optimizer )
# Single GPU
solver = core . Engine ( task , train_set , valid_set , test_set , optimizer , gpus = [ 0 ])
# Multiple GPUs
solver = core . Engine ( task , train_set , valid_set , test_set , optimizer , gpus = [ 0 , 1 , 2 , 3 ])
# Distributed GPUs
solver = core . Engine ( task , train_set , valid_set , test_set , optimizer , gpus = [ 0 , 1 , 2 , 3 , 0 , 1 , 2 , 3 ])実験は、Weights&Biaseプラットフォームを介して簡単に追跡および管理できます。
solver = core . Engine ( task , train_set , valid_set , test_set , optimizer , logger = "wandb" )誰もがTorchdrugの開発に貢献できます。詳細については、貢献ガイドラインを参照してください。
TorchdrugはApache-2.0ライセンスの下でリリースされます。