Computes output variables and grows the computational graph. Basic behavior is expressed in the documentation of :class:`FunctionNode`. .. note:: If the :data:`~Variable.data` attributes of the input variables exist on a GPU device, that device is mad
(self, inputs)
| 240 | raise RuntimeError(msg) |
| 241 | |
| 242 | def apply(self, inputs): |
| 243 | """Computes output variables and grows the computational graph. |
| 244 | |
| 245 | Basic behavior is expressed in the documentation of |
| 246 | :class:`FunctionNode`. |
| 247 | |
| 248 | .. note:: |
| 249 | |
| 250 | If the :data:`~Variable.data` attributes of the input variables |
| 251 | exist on a GPU device, that device is made current before calling |
| 252 | :meth:`forward`, so implementers do not need to take care of device |
| 253 | selection in most cases. |
| 254 | |
| 255 | Args: |
| 256 | inputs: Tuple of input variables. Each element can be either |
| 257 | :class:`~chainer.Variable` or :ref:`ndarray`. If the element |
| 258 | is an ndarray, it is automatically wrapped with |
| 259 | :class:`~chainer.Variable`. |
| 260 | |
| 261 | Returns: |
| 262 | A tuple of output :class:`~chainer.Variable` objects. |
| 263 | |
| 264 | """ |
| 265 | chainerx_in_data = None |
| 266 | chainerx_device = None |
| 267 | is_chainerx, in_data = _extract_apply_in_data(inputs) |
| 268 | |
| 269 | utils._check_arrays_forward_compatible(in_data, self.label) |
| 270 | |
| 271 | if is_chainerx: |
| 272 | # Try ChainerX C++ implementation. |
| 273 | # If it's supported, the output arrays are wrapped with Variables |
| 274 | # and returned. |
| 275 | # If not supported, FunctionNode.forward_chainerx should return |
| 276 | # Fallback. |
| 277 | # In that case the input arrays are converted to numpy.ndarray |
| 278 | # or cupy.ndarray (depending on the ChainerX backend) and |
| 279 | # forward computation falls back to the conventional |
| 280 | # FunctionNode.forward() implementaion. |
| 281 | outputs = self.forward_chainerx(in_data) |
| 282 | |
| 283 | if outputs is not chainer.Fallback: |
| 284 | # Supported. Wrap with variables and return |
| 285 | assert isinstance(outputs, tuple) |
| 286 | return tuple([ |
| 287 | variable.Variable._init_unchecked( |
| 288 | y, requires_grad=y.is_backprop_required(), |
| 289 | is_chainerx_array=True) |
| 290 | for y in outputs]) |
| 291 | |
| 292 | # Fall back to FunctionNode.forward() |
| 293 | chainerx_in_data, in_data, chainerx_device = ( |
| 294 | self._chainerx_apply_fallback_preprocess(in_data, inputs)) |
| 295 | self._is_chainerx_fallback_mode = True |
| 296 | self.chainerx_device = chainerx_device |
| 297 | |
| 298 | is_debug = chainer.is_debug() |
| 299 | if is_debug: |