Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PhysicsTools/PyTorch/interface/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace cms::torch {
if (dev == device_)
return;

assert(!is_frozen_ && "Model is frozen, cannot be moved to another device!");
TORCH_CHECK(!is_frozen_ && "Model is frozen, cannot be moved to another device!");
model_.to(dev, non_blocking);
device_ = dev;
if (auto_freeze_) {
Expand Down
10 changes: 9 additions & 1 deletion PhysicsTools/PyTorch/test/testModelJit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,22 @@ namespace torchtest {

auto m_path = edm::FileInPath(modelPath).fullPath();
forEachCudaDevice([&](auto dev) {
auto m = cms::torch::Model(m_path);
auto m = cms::torch::Model(m_path, false);
m.to(dev);

CPPUNIT_ASSERT_EQUAL(dev, m.device());

m.to(::torch::kCPU);
CPPUNIT_ASSERT_EQUAL(::torch::kCPU, m.device().type());
});

forEachCudaDevice([&](auto dev) {
auto m = cms::torch::Model(m_path);
m.to(dev);

CPPUNIT_ASSERT_EQUAL(dev, m.device());
CPPUNIT_ASSERT_THROW(m.to(::torch::kCPU), c10::Error);
});
}

void TestModelJIT::testToDevice_NonBlocking() {
Expand Down