mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Support custom exception message (#41907)
Summary: Raise and assert used to have a hard-coded error message "Exception". User provided error message was ignored. This PR adds support to represent user's error message in TorchScript. This breaks backward compatibility because now we actually need to script the user's error message, which can potentially contain unscriptable expressions. Such programs can break when scripting, but saved models can still continue to work. Increased an op count in test_mobile_optimizer.py because now we need aten::format to form the actual exception message. This is built upon an WIP PR: https://github.com/pytorch/pytorch/pull/34112 by driazati Pull Request resolved: https://github.com/pytorch/pytorch/pull/41907 Reviewed By: ngimel Differential Revision: D22778301 Pulled By: gmagogsfm fbshipit-source-id: 2b94f0db4ae9fe70c4cd03f4048e519ea96323ad
This commit is contained in:
committed by
Facebook GitHub Bot
parent
5769b06ab5
commit
bdcf320bed
@ -377,9 +377,8 @@ class LOBPCG(object):
|
||||
# strict ordering of eigenpairs
|
||||
break
|
||||
count += 1
|
||||
assert count >= prev_count, (
|
||||
'the number of converged eigenpairs '
|
||||
'(was %s, got %s) cannot decrease' % (prev_count, count))
|
||||
assert count >= prev_count, 'the number of converged eigenpairs ' \
|
||||
'(was {}, got {}) cannot decrease'.format(prev_count, count)
|
||||
self.ivars['converged_count'] = count
|
||||
self.tvars['rerr'] = rerr
|
||||
return count
|
||||
@ -723,10 +722,14 @@ class LOBPCG(object):
|
||||
if rerr < tau_ortho:
|
||||
break
|
||||
if m < U.shape[-1] + V.shape[-1]:
|
||||
# TorchScript needs the class var to be assigned to a local to
|
||||
# do optional type refinement
|
||||
B = self.B
|
||||
assert B is not None
|
||||
raise ValueError(
|
||||
'Overdetermined shape of U:'
|
||||
' #B-cols(={}) >= #U-cols(={}) + #V-cols(={}) must hold'
|
||||
.format(self.B.shape[-1], U.shape[-1], V.shape[-1]))
|
||||
.format(B.shape[-1], U.shape[-1], V.shape[-1]))
|
||||
self.ivars['ortho_i'] = i
|
||||
self.ivars['ortho_j'] = j
|
||||
return U
|
||||
|
Reference in New Issue
Block a user