Open
Description
Description
import scipy.sparse
import pytensor
import pytensor.tensor as pt
import pytensor.sparse as ps
X_sp = scipy.sparse.random(100, 5, density=0.25, dtype="float64").tocsc()
X_pt = ps.as_sparse_variable(X_sp)
beta_pt = pt.vector("beta")
out = ps.dot(X_pt, beta_pt)
fn = pytensor.function([beta_pt], out, mode="NUMBA") # Works fine with "FAST_COMPILE"
fn([0, 1, 2, 3, 4])
Traceback
/home/ricardo/Documents/Projects/pytensor/pytensor/link/numba/dispatch/basic.py:374: UserWarning: Numba will use object mode to run SparseDot's perform method warnings.warn( Traceback (most recent call last): File "/home/ricardo/Documents/Projects/pytensor/pytensor/link/utils.py", line 202, in streamline_default_f thunk() File "/home/ricardo/Documents/Projects/pytensor/pytensor/link/basic.py", line 669, in thunk outputs = fgraph_jit(*[x[0] for x in thunk_inputs]) File "/home/ricardo/miniconda3/envs/pytensor/lib/python3.10/site-packages/numba/core/dispatcher.py", line 468, in _compile_for_args error_rewrite(e, 'typing') File "/home/ricardo/miniconda3/envs/pytensor/lib/python3.10/site-packages/numba/core/dispatcher.py", line 409, in error_rewrite raise e.with_traceback(None) numba.core.errors.NumbaNotImplementedError: Failed in nopython mode pipeline (step: native lowering) , (csc_matrix,) During: lowering "$4load_global.1 = global(sparse_constant: (1, 0) 0.6193231190372754 (5, 0) 0.8740048873975508 (6, 0) 0.7925578534721608 (9, 0) 0.19269518223105275 (12, 0) 0.1839731129406018 (13, 0) 0.21843307412585022 (17, 0) 0.7559395383363388 (21, 0) 0.2578475824668185 (24, 0) 0.24902662098970674 (27, 0) 0.5662721861445259 (36, 0) 0.28595768449838865 (37, 0) 0.5112625740463957 (43, 0) 0.3950046413360234 (45, 0) 0.9139339022582337 (47, 0) 0.9826060837861639 (56, 0) 0.1716812875025585 (70, 0) 0.22661361564743931 (73, 0) 0.8108463427431011 (79, 0) 0.5335349962088054 (80, 0) 0.06042505755716465 (85, 0) 0.5723897478252526 (89, 0) 0.4458495087002704 (92, 0) 0.3434520517764187 (93, 0) 0.8646593646654596 (0, 1) 0.5243562732369695 : : (99, 3) 0.20118629041982228 (1, 4) 0.8240736094296793 (8, 4) 0.7564835995438847 (13, 4) 0.5685153360939462 (19, 4) 0.7344933059825828 (20, 4) 0.7264022805497009 (22, 4) 0.6428913277968995 (25, 4) 0.3790812712494276 (26, 4) 0.29904472032607254 (31, 4) 0.9989894714423738 (37, 4) 0.3512987174303843 (39, 4) 0.48184082667688166 (42, 4) 0.6306614965054567 (51, 4) 0.504339194411603 (67, 4) 0.9762186943259413 (68, 4) 0.3894187556430818 (69, 4) 0.6267504548119234 (72, 4) 0.5917477331276589 (75, 4) 0.35109838617423883 (84, 4) 0.4892804415154173 (85, 4) 0.8300351684927277 (88, 4) 0.6250239669632559 (92, 4) 0.5354533131478953 (95, 4) 0.879833135981891 (99, 4) 0.5119340141069734)" at /tmp/tmpd8r0g8ei (3) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/ricardo/miniconda3/envs/pytensor/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3433, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 12, in fn([0, 1, 2, 3, 4]) File "/home/ricardo/Documents/Projects/pytensor/pytensor/compile/function/types.py", line 970, in __call__ self.vm() File "/home/ricardo/Documents/Projects/pytensor/pytensor/link/utils.py", line 206, in streamline_default_f raise_with_op(fgraph, node, thunk) File "/home/ricardo/Documents/Projects/pytensor/pytensor/link/utils.py", line 535, in raise_with_op raise exc_value.with_traceback(exc_trace) File "/home/ricardo/Documents/Projects/pytensor/pytensor/link/utils.py", line 202, in streamline_default_f thunk() File "/home/ricardo/Documents/Projects/pytensor/pytensor/link/basic.py", line 669, in thunk outputs = fgraph_jit(*[x[0] for x in thunk_inputs]) File "/home/ricardo/miniconda3/envs/pytensor/lib/python3.10/site-packages/numba/core/dispatcher.py", line 468, in _compile_for_args error_rewrite(e, 'typing') File "/home/ricardo/miniconda3/envs/pytensor/lib/python3.10/site-packages/numba/core/dispatcher.py", line 409, in error_rewrite raise e.with_traceback(None) numba.core.errors.NumbaNotImplementedError: Failed in nopython mode pipeline (step: native lowering) , (csc_matrix,) During: lowering "$4load_global.1 = global(sparse_constant: (1, 0) 0.6193231190372754 (5, 0) 0.8740048873975508 (6, 0) 0.7925578534721608 (9, 0) 0.19269518223105275 (12, 0) 0.1839731129406018 (13, 0) 0.21843307412585022 (17, 0) 0.7559395383363388 (21, 0) 0.2578475824668185 (24, 0) 0.24902662098970674 (27, 0) 0.5662721861445259 (36, 0) 0.28595768449838865 (37, 0) 0.5112625740463957 (43, 0) 0.3950046413360234 (45, 0) 0.9139339022582337 (47, 0) 0.9826060837861639 (56, 0) 0.1716812875025585 (70, 0) 0.22661361564743931 (73, 0) 0.8108463427431011 (79, 0) 0.5335349962088054 (80, 0) 0.06042505755716465 (85, 0) 0.5723897478252526 (89, 0) 0.4458495087002704 (92, 0) 0.3434520517764187 (93, 0) 0.8646593646654596 (0, 1) 0.5243562732369695 : : (99, 3) 0.20118629041982228 (1, 4) 0.8240736094296793 (8, 4) 0.7564835995438847 (13, 4) 0.5685153360939462 (19, 4) 0.7344933059825828 (20, 4) 0.7264022805497009 (22, 4) 0.6428913277968995 (25, 4) 0.3790812712494276 (26, 4) 0.29904472032607254 (31, 4) 0.9989894714423738 (37, 4) 0.3512987174303843 (39, 4) 0.48184082667688166 (42, 4) 0.6306614965054567 (51, 4) 0.504339194411603 (67, 4) 0.9762186943259413 (68, 4) 0.3894187556430818 (69, 4) 0.6267504548119234 (72, 4) 0.5917477331276589 (75, 4) 0.35109838617423883 (84, 4) 0.4892804415154173 (85, 4) 0.8300351684927277 (88, 4) 0.6250239669632559 (92, 4) 0.5354533131478953 (95, 4) 0.879833135981891 (99, 4) 0.5119340141069734)" at /tmp/tmpd8r0g8ei (3) Apply node that caused the error: SparseDot(SparseConstant{csc,float64,shape=(100, 5),nnz=125}, beta) Toposort index: 0 Inputs types: [Sparse(float64, (100, 5), csc), TensorType(float64, (?,))] Inputs shapes: [(5,)] Inputs strides: [(8,)] Inputs values: [array([0., 1., 2., 3., 4.])] Outputs clients: [['output']] Backtrace when the node is created (use PyTensor flag traceback__limit=N to make it longer): File "/snap/pycharm-community/327/plugins/python-ce/helpers/pydev/_pydev_bundle/pydev_ipython_console_011.py", line 411, in add_exec res = self.ipython.run_cell(line, store_history=True) File "/home/ricardo/miniconda3/envs/pytensor/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2940, in run_cell result = self._run_cell( File "/home/ricardo/miniconda3/envs/pytensor/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 2995, in _run_cell return runner(coro) File "/home/ricardo/miniconda3/envs/pytensor/lib/python3.10/site-packages/IPython/core/async_helpers.py", line 129, in _pseudo_sync_runner coro.send(None) File "/home/ricardo/miniconda3/envs/pytensor/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3194, in run_cell_async has_raised = await self.run_ast_nodes(code_ast.body, cell_name, File "/home/ricardo/miniconda3/envs/pytensor/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3373, in run_ast_nodes if await self.run_code(code, result, async_=asy): File "/home/ricardo/miniconda3/envs/pytensor/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3433, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 10, in out = ps.dot(X_pt, beta_pt) HINT: Use the PyTensor flag `exception_verbosity=high` for a debug print-out and storage map footprint of this Apply node.It does work with symbolic inputs
X_nonconst_pt = X_pt.type()
out = ps.dot(X_nonconst_pt, beta_pt)
fn = pytensor.function([X_nonconst_pt, beta_pt], out, mode="NUMBA")
fn(X_sp, [0, 1, 2, 3, 4])