に並列にPythonコードの部分を実行する2つの異なる方法(method1
とmethod2
)でスクリプトを実行するために私は次のようなPyTorchスクリプト有する二つの異なるGPUを
# Loading data
train_loader, test_loader = someDataLoaderFunction()
# Define the architecture
model = ResNet18()
model = model.cuda()
# Get method from program argument
method = args.method
# Training
train(method, model, train_loader, test_loader)
を、それが十分で二つの異なる端末で次のコマンドを実行する:問題がある
CUDA_VISIBLE_DEVICES=0 python program.py --method method1
CUDA_VISIBLE_DEVICES=1 python program.py --method method2
、上記データローダ関数は、2つの方法が2つに適用されたことを意味し、その中のいくつかのランダムを含有します異なるトレーニングデータセット。私は、データの正確な同じセットを訓練するためにそれらをしたいと思いますので、以下のように、私は、スクリプトを修正:
# Loading data
train_loader, test_loader = someDataLoaderFunction()
# Define the architecture
model = ResNet18()
model = model.cuda()
## Run for the first method
method = 'method1'
# Training
train(method, model, train_loader, test_loader)
## Run for the second method
method = 'method2'
# Must re-initialize the network first
model = ResNet18()
model = model.cuda()
# Training
train(method, model, train_loader, test_loader)
それはそれぞれの方法について並列に実行させることは可能ですか? あらかじめご協力いただきありがとうございます!
Umm、並列コンピューティングは、まったく異なるコーディングアーキテクチャを必要とします。私ができることは、Python 3の 'queue' inbuilt libを指し示すことです。それを使ってパラレル実行のオーケストレーションを行う必要があります。また、競合状態とスレッドロックについて読んでください。そうしないと、コードフラストレーションが発生する可能性があります。 – aim100k
@ aim100kありがとう。私はC++やMatlabのループのようないくつかの基本的なものしか出していませんでした。( – Khue
あなたのウェブサイトを見て、あなたがしていることが本当に素晴らしいと思います。あなたはここで答えを見つけます – aim100k