-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backward headgrads and detach (#6332)
* backward headgrads and detach lint fix add updated grad add retain grad exclude reduce cpp cached invoke cached symbol move symbol init module symbol cython udpate updated_grad->fresh_grad fix * fix
- Loading branch information
Showing
29 changed files
with
1,018 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# coding: utf-8 | ||
"""Common code between symbolic and ndarray.""" | ||
from __future__ import absolute_import as _abs | ||
|
||
import ctypes | ||
|
||
from ..base import _LIB | ||
from ..base import c_array, c_str | ||
from ..base import OpHandle, CachedOpHandle | ||
from ..base import check_call | ||
|
||
|
||
class CachedOp(object): | ||
"""Cached operator handle.""" | ||
__slots__ = ["handle", "op"] | ||
def __init__(self, op, num_input, **kwargs): | ||
self.op = op | ||
op_handle = OpHandle() | ||
check_call(_LIB.NNGetOpHandle(c_str(op), ctypes.byref(op_handle))) | ||
self.handle = CachedOpHandle() | ||
check_call(_LIB.MXCachedCreateOp( | ||
op_handle, | ||
ctypes.c_int(num_input), | ||
ctypes.c_int(len(kwargs)), | ||
c_array(ctypes.c_char_p, [c_str(key) for key in kwargs.keys()]), | ||
c_array(ctypes.c_char_p, [c_str(str(val)) for val in kwargs.values()]), | ||
ctypes.byref(self.handle))) | ||
|
||
def __del__(self): | ||
check_call(_LIB.MXCachedFree(self.handle)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.