  
                          terms.append(term)
  
-@@ -1318,6 +1326,7 @@
+@@ -1318,6 +1332,7 @@
                  # this variable isn't connected to the cost in the
                  # computational graph
                  grad_dict[var] = disconnected_type()

-                                ("%s.grad returned a term with"
-                                 " %d dimensions, but %d are required.") % (
-                                     str(node.op), term.ndim, var.ndim))
+                        # if hasattr(var, 'ndim') and term.ndim != var.ndim:
+                        #     raise ValueError(
+                        #         ("%s.grad returned a term with"

                 input_grads = node.op.grad(inputs, new_output_grads)
 
                 if input_grads is None:
@@ -1292,11 +1300,17 @@
                         if isinstance(term.type, DisconnectedType):
                             continue
 
