Commit c1b8f912 by Ting PAN

Merge internal commits

1 parent ae11a987
Showing with 168 additions and 4626 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

---
AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [FOR_EACH_RANGE, FOR_EACH]
IncludeCategories:
- Regex: '^<.*\.h(pp)?>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...
[flake8]
max-line-length = 120
ignore = E741, # ambiguous variable name
F403, # ‘from module import *’ used; unable to detect undefined names
F405, # name may be undefined, or defined from star imports: module
F811, # redefinition of unused name from line N
F821, # undefined name
W503, # line break before binary operator
W504, # line break after binary operator
# module imported but unused
per-file-ignores = __init__.py: F401
exclude = third_party, *_pb2.py
---
name: Bug Report
about: Use this template for reporting a bug
labels: type:bug
---
## Environment
### Hardware:
- Computing Device:
### Software:
- OS Platform (e.g., Linux Ubuntu 16.04):
- Python Version:
- CUDA/CUDNN Version:
- Distributed Version / Installed From (``pip``, ``source``):
## Describe the current behavior
## Describe the expected behavior
## How to reproduce this issue
## Info / Logs
---
name: Documentation Issue
about: Use this template for documentation issues
labels: type:docs
---
## URL with the issue
Provide the link to the documentation pages or sources.
## Description
### Brief
Is the brief clearly describe the method?
### Parameters
Are all parameters formatted correctly?
### Return values
Is the type or brief of return values wrong?
### Usages / Examples
Are usages or examples matched to the results?
......@@ -43,8 +43,13 @@ __pycache__
# VSCode files
.vscode
# PyCharm files
# IDEA files
.idea
# OSX dir files
.DS_Store
\ No newline at end of file
.DS_Store
# Android files
.gradle
*.iml
local.properties
[submodule "DragonBoard"]
path = DragonBoard
url = git://github.com/seetaresearch/DragonBoard.git
[submodule "DragonLair"]
path = DragonLair
url = https://github.com/seetaresearch/DragonLair.git
[submodule "ThirdParty/eigen"]
path = ThirdParty/eigen
url = https://github.com/eigenteam/eigen-git-mirror.git
[submodule "ThirdParty/cub"]
path = ThirdParty/cub
[submodule "third_party/cub"]
path = third_party/cub
url = https://github.com/NVlabs/cub
[submodule "ThirdParty/pybind11"]
path = ThirdParty/pybind11
[submodule "third_party/eigen"]
path = third_party/eigen
url = https://gitlab.com/libeigen/eigen
[submodule "third_party/pybind11"]
path = third_party/pybind11
url = https://github.com/pybind/pybind11
------------------------------------------------------------------------
The list of most significant changes made over time in Dragon.
Dragon 0.3.0.0 (20190402)
DRAGON_VERSION == 3000
Changes (w.r.t. Dragon 0.2.2.13):
Preview Features:
- New V.M framework: ONNX
We have extended the exporting and importing(Runtime) for ONNX.
- Operators Refactor:
* <NDArray> Faster implementation for following multiple axes operators:
``Crop``, ``Pad``, ``Tile``, ``Reduce`` and ``Transpose``.
* <Norm> Faster implementation for fused norm operators:
``BatchNorm``, ``GroupNorm``, ``LayerNorm``, ``InstanceNorm``.
- Use ``Eigen`` as the default cpu math library instead of ``OpenBLAS``.
- Use ``PyBind11`` as the default python module exporter.
- Integer data types support for common operators,
see the documentation for more detail information.
- A new workspace-local dummy name interface has been introduced,
which unifies the naming of static and dynamic computation graph.
- The behavior of accumulating gradients have been canceled.
- Python module now has been assigned to take charge of ``Workspace``.
Bugs fixed:
- Repair the basic TensorFlow API, following the master branch.
- More reliable shape inference for static computation graph.
------------------------------------------------------------------------
Dragon 0.2.2.13 (20181204)
DRAGON_VERSION == 2213
Changes (w.r.t. Dragon 0.2.2.12):
Preview Features:
- Dismantled op kernels.
- Added FP16 support for ``NNResizeOp``, ``ProposalOp``,
``ROIPoolingOp``, ``ROIAlignOp``, (R-CNN components).
- Added ``DepthwiseConv2dOp``.
- [PyTorch] Added ``nn.DepthwiseConv2d``
- [PyCaffe] Added ``DepthwiseConvolutionLayer``.
Bugs fixed:
- Fixed the cuda issue that incorrect results in ``AsTypeOp``
under ``float32 -> float16``.
- Removed the support for group convolution implemented with im2col-nhwc.
- Changed the default ``NHWC`` pack format of filter from
``[filter_height, filter_width, in_channels, out_channels]``(TensorFlow) to
``[out_channels, filter_height, filter_width, in_channels]``(CuDNN).
- Changed the VC Runtime from ``MD`` to ``MT``.
------------------------------------------------------------------------
Dragon 0.2.2.12 (20181120)
DRAGON_VERSION == 2212
Changes (w.r.t. Dragon 0.2.2.11):
Preview Features:
- Added Cambricon's CNML context.
- Added the support for Int8(Char) Tensor.
- Removed the cuda device id query from pointer.
- Added ``DropBlock2dOp``
- Added ``MaximumOp``, ``MinimumOp``, ``NLLLossOp``.
- Added CuDNN support for ``BiasAddOp``.
- Optimized memory usage of ``DropoutOp``.
- Replaced ``thread_local`` with platform TLS solution.
- Changed the default norm eps from 1e-3 to 1e-5,
affected: ``BatchNorm``, ``BatchRenorm``, ``GroupNorm``, ``InstanceNorm``, ``L2Norm``.
- Enforced CUDA FP16 support (i.e. Removed ``WITH_CUDA_FP16``).
- [PyTorch] Added ``torch.one_hot``.
- [PyTorch] Added ``torch.log``, ``Tensor.log``, ``torch.exp`` and ``Tensor.exp``.
- [PyTorch] Added ``torch.minimum``, ``torch.maximum``,
``torch.clamp``, ``Tensor.clamp``, ``Tensor.clamp_``.
- [PyTorch] Added ``nn.ELU`` and ``nn.SELU``.
- [PyTorch] Added ``nn.GroupNorm``.
- [PyTorch] Added ``nn.NLLLoss``, ``nn.BCEWithLogitsLoss``,
``nn.L1Loss``, ``nn.MSELoss``, ``nn.SmoothL1Loss``.
- [PyTorch] Added ``nn.DropBlock2d``.
- [PyTorch] Added ``train`` and ``eval`` mode for Module,
affected: ``nn.BatchNorm``, ``nn.Dropout``.
- [PyTorch] Deprecated the ``size_average`` and ``reduce`` in
``nn.Loss``, added ``reduction`` instead.
- [PyTorch] ``torch.save`` can save both ``torch.Tensor`` and other pickle values.
- [PyCaffe] Added ``DropBlockLayer``.
Bugs fixed:
- Fixed the uncomputed output in ``BiasAddGradientOp``.
- Fixed the incorrect gradients of ``ClipGradientOp``.
- Fixed the wrong results of ``math::Inv`` under ``CPUContext``.
- Fixed the issue that the default device is used on initializing NCCL.
- Removed the strictly shape check in ``SmoothL1Op``.
- Fixed wrong CXX API exporting under Win32.
- [PyTorch] Fixed an issue that multiple ``GradientGather`` are triggered by one Operator.
- [PyTorch] Fixed the schema check by in-place fundamental ops.
- [PyTorch] Fixed the missing shape and dtype after ``Tensor.copy_``.
- [PyTorch] Fixed an issue that ``Tensor.fill_`` and ``Tensor.zero_``
will change the data type of an non-empty Tensor.
- [PyTorch] Fixed the Python2 Int(s) check.
------------------------------------------------------------------------
\ No newline at end of file
"""Sphinx extension provide a new directive *mathmacro*.
This extension has to be added after the other math extension since it
redefined the math directive and the math role. For example, like this
(in the conf.py file)::
extensions = [
'sphinx.ext.autodoc', 'sphinx.ext.doctest',
'sphinx.ext.mathjax',
'sphinx.ext.viewcode', 'sphinx.ext.autosummary',
'numpydoc',
'mathmacro']
"""
from __future__ import print_function
import re
from docutils.parsers.rst.directives.misc import Replace
from sphinx.ext.mathbase import MathDirective
from sphinx.ext.mathbase import math_role
def multiple_replacer(replace_dict):
"""Return a function replacing doing multiple replacements.
The produced function replace `replace_dict.keys()` by
`replace_dict.values`, respectively.
"""
def replacement_function(match):
s = match.group(0)
end = s[-1]
if re.match(r'[\W_]', end):
return replace_dict[s[:-1]]+end
else:
return replace_dict[s]
pattern = "|".join([re.escape(k)+r'[\W_]'
for k in replace_dict.keys()])
pattern = re.compile(pattern, re.M)
return lambda string: pattern.sub(replacement_function, string)
def multiple_replace(string, replace_dict):
mreplace = multiple_replacer(replace_dict)
return mreplace(string)
class MathMacro(Replace):
"""Directive defining a math macro."""
def run(self):
if not hasattr(self.state.document, 'math_macros'):
self.state.document.math_macros = {}
latex_key = '\\'+self.state.parent.rawsource.split('|')[1]
self.state.document.math_macros[latex_key] = ''.join(self.content)
self.content[0] = ':math:`'+self.content[0]
self.content[-1] = self.content[-1]+'`'
return super(MathMacro, self).run()
class NewMathDirective(MathDirective):
"""New math block directive parsing the latex code."""
def run(self):
try:
math_macros = self.state.document.math_macros
except AttributeError:
pass
else:
if math_macros:
multiple_replace = multiple_replacer(math_macros)
for i, c in enumerate(self.content):
self.content[i] = multiple_replace(c)
for i, a in enumerate(self.arguments):
self.arguments[i] = multiple_replace(a)
return super(NewMathDirective, self).run()
def new_math_role(role, rawtext, text, lineno, inliner,
options={}, content=[]):
"""New math role parsing the latex code."""
try:
math_macros = inliner.document.math_macros
except AttributeError:
pass
else:
if math_macros:
rawtext = multiple_replace(rawtext, math_macros)
text = rawtext.split('`')[1]
return math_role(role, rawtext, text, lineno, inliner,
options=options, content=content)
def setup(app):
app.add_role('math', new_math_role)
app.add_directive('math', NewMathDirective)
app.add_directive('mathmacro', MathMacro)
\ No newline at end of file
/*-------------------- basics --------------------*/
body {
font-size: 16px;
font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif;
}
table.field-list {
width: 100%;
}
.field-list ul {
padding-left: 0;
}
.field-name {
width: 110px;
}
code.descname,
code.descclassname {
color: #555
}
div.admonition {
padding: 16px;
background-color: #f6f8fa;
border: 1px solid rgb(204, 204, 204);
border-radius: 4px;
}
p.admonition-title {
color: #187dbb;
margin: 0px 10px 5px 0px;
font-weight: bold;
font-size: 16px;
line-height: 1.5em;
}
p.last {
font-size: 16px;
color: #000;
}
p {
margin: 0px 0px 21px 0px
}
.footer {
width: 0
}
h1 {
margin-bottom: 25px;
}
h2 {
margin-bottom: 21px;
}
h3 {
margin-top: 10.5px;
margin-bottom: 30px;
}
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
font-family: "Lato"
}
a {
color: #2786e0;
text-decoration: none;
}
a:hover, a:focus {
color: #902594;
text-decoration: none;
}
.context {
display: none
}
/*-------------------- layout --------------------*/
.container.doc-container {
width: 97%;
}
div.content {
padding: 0px 30px 0px 30px;
float: right;
width: calc(100% - 345px);
}
@media (max-width: 999px) {
div.content {
overflow-x: auto;
width: 100%;
}
}
.section:before {
content: " ";
display: block;
height: 60px;
margin: -60px 0 0;
}
/*-------------------- navbar-brand --------------------*/
.navbar-default .navbar-brand {
font-size: 25px;
font-weight: bold;
}
.navbar-brand {
height: 60px;
}
/*-------------------- navbar-main --------------------*/
.navbar {
#background-color: #2695ff;
background: linear-gradient(to right, #4070a0, #5bc0de);
border: 0px;
margin-bottom: 0px;
opacity: 0.9
}
.navbar-inverse .navbar-collapse {
background-color: transparent;
}
.navbar-nav {
font-size: 18px;
margin-left: 25px;
}
.navbar .container {
width: 97%
}
/*-------------------- navbar-item --------------------*/
.navbar-nav>li {
-webkit-transition: .2s;
transition: .2s;
display: inline-block;
padding: 7px 15px;
}
.navbar-inverse .navbar-nav>li>a {
opacity: .7;
}
.navbar-inverse .navbar-nav>li>a:hover {
opacity: 1;
color: #fff;
text-decoration: none;
}
.navbar-inverse .navbar-nav>li>a:hover,
.navbar-inverse .navbar-nav>li>a:focus {
color: #ffffff;
background-color: transparent
}
.navbar-inverse .navbar-nav>.open>a:active,
.navbar-inverse .navbar-nav>.open>a:hover,
.navbar-inverse .navbar-nav>.open>a:focus {
background-color: transparent;
text-align: center;
}
.navbar-inverse .navbar-nav>.open>a {
background-color: transparent;
}
/*-------------------- navbar-dropdown --------------------*/
.navbar-inverse .navbar-nav>.open .dropdown-menu > li > a,
.navbar-inverse .navbar-nav .open .dropdown-menu>li>a:hover,
.navbar-inverse .navbar-nav .open .dropdown-menu>li>a:focus {
color: #4070a0;;
background-color: white;
box-shadow: 0px 1px 1px 1px;
}
.navbar-inverse .navbar-nav .open .dropdown-menu>li>a:hover {
background-color: white;
color: #5bc0de;
}
.navbar-inverse .dropdown-menu {
background-color: #fff;
top: 100%;
border-radius: 3px;
text-align: center;
opacity: 0.95;
}
.navbar-nav .open .dropdown-menu {
float: left;
border-color: rgba(38, 149, 255, 0.32);
}
.navbar .dropdown-menu {
border:none;
}
.navbar-inverse .dropdown-menu>li>a:hover {
color: #0a5655;
background-color: #f5f5f5;
}
.navbar-inverse .navbar-nav>.open>a:hover,
.navbar-inverse .navbar-nav>.open>a:focus {
text-align: left;
}
.navbar .dropdown-menu>li>a, .navbar .dropdown-menu>li>a:focus {
font-size: 16px;
font-weight: 600;
}
.navbar-inverse .navbar-nav>.open .dropdown-menu > li > a {
color: #4070a0;
padding: 8px;
}
.navbar-nav>li>.dropdown-menu {
margin-top: 1px;
}
/*-------------------- navbar-search --------------------*/
.navbar-inverse .navbar-form {
border-color: #2695ff;
padding-top: 7px;
padding-bottom: 1px;
border: none;
}
.navbar-form .form-control {
border-radius: 5px;
}
.navbar-toggle {
padding: 0px 0px;
margin-top: 20px;
}
/*-------------------- code --------------------*/
.xref.py.py-mod.docutils.literal {
color: #103d3e;
background-color: #ffffff;
font-size: 40px;
font-family: Consolas;
padding: 0px;
}
.xref.py.py-mod.docutils.literal:target {
background-color: #e7f2fa;
border-bottom: 3px solid #c7254e;
margin-bottom: -3px;
}
code.docutils.literal {
color: #32577b;
font-family: Lato;
font-weight: bold;
font-size: 14px;
}
code.docutils.literal:hover {
color: #902594;
}
.highlight-python {
margin-bottom: 21px;
}
dt {
font-weight: 700;
background: #f7f7f7;
border-bottom: solid #0079b2;
border-radius: 8px;
margin-bottom: 20px;
padding: 8px;
width: 75%;
}
dt:target, .highlighted {
background-color: #f7f7f7;
border-bottom: 3px solid #c7254e;
}
dt:target:before {
background-color: white;
content: '';
display: block;
height: 65px;
margin: -20px -8px 8px;
}
dl.method dt {
background: #f0f0f0;
border-bottom: solid #ccc;
}
dt em {
font-weight: normal;
font-style: normal;
font-size: 90%;
}
dd {
margin-top: 3px;
margin-bottom: 10px;
margin-left: 30px;
}
table {
font-size: 16px;
}
table.table tr, td, th {
padding-top: 5px;
padding-bottom: 5px;
padding-left: 10px;
padding-right: 10px;
border: 1px solid rgb(223, 226, 229);
}
table.field-list.table tr {
border: 0px solid rgb(223, 226, 229);
}
blockquote {
border-left-width: 0px;
color: #6f6f6f;
padding: 10.5px 21px;
margin: 0 0 21px;
font-size: 17px;
border-left: 5px solid #dddddd;
background-color: #f6f8fa;
border: 1px solid rgb(204, 204, 204);
border-radius: 4px;
max-width: 750px;
}
ul.simple li {
margin-bottom: 10px;
margin-left: 10px;
}
/*------------------sidebar-----------------------*/
div.sphinxsidebar {
position: fixed;
overflow: auto;
display: none;
height: calc(100% - 40px);
}
div.leftsidebar {
width: 300px;
margin-left: 25px;
background: transparent;
}
@media (min-width: 1000px) {
div.sphinxsidebar {display: block}
}
div.sphinxsidebar ul {
padding-left: 25px;
list-style-type: none !important;
}
div.sphinxsidebar li {
padding-top: 5px;
margin-bottom: 5px;
margin-left: -10px;
}
div.sphinxsidebarwrapper {
padding: 60px 10px 60px 20px;
background: transparent;
}
div.sphinxsidebar ul ul {
margin-left: 0px;
padding-top: 3px;
}
div.sphinxsidebar li.opened .tocToggle:before {
font-family: 'FontAwesome';
content: "\f115";
margin: 0 5px 0 -15px;
color: #2695ff;
}
div.sphinxsidebar li.closed .tocToggle:before {
font-family: 'FontAwesome';
content: "\f0fe";
margin: 0 5px 0 -15px;
color: #2695ff;
}
div.sphinxsidebar li.leaf .tocToggle:before {
font-family: 'FontAwesome';
content: "\f101";
margin: 0 5px 0 -15px;
color: #2695ff;
}
div.sphinxsidebar li.focused .tocToggle:before {
font-family: 'FontAwesome';
content: "\f06e";
margin: 0 5px 0 -15px;
color: #2695ff;
}
/*-------------------- install --------------------*/
.opt-group {
margin-top: 10px;
margin-bottom: 10px;
}
.btn-default {
color: #333;
background-color: #fff;
border-color: #ccc;
}
.btn-default:hover, .btn-default:focus, .btn-default:active, .btn-default.active.focus,
.btn-default.active:focus, .btn-default.active:hover, .btn-default:active.focus, .btn-default:active:focus,
.btn-default:active:hover, .btn-default.active, .open>.dropdown-toggle.btn-default, .btn-default:active:focus {
color: #fff;
background-color: #0079b2;
border-color: #0079b2;
}
\ No newline at end of file
(function ($) {
/**
* Patch TOC list.
*
* Will mutate the underlying span to have a correct ul for nav.
*
* @param $span: Span containing nested UL"s to mutate.
* @param minLevel: Starting level for nested lists. (1: global, 2: local).
*/
var patchToc = function ($ul, minLevel) {
var findA,
patchTables,
$localLi;
// Find all a "internal" tags, traversing recursively.
findA = function ($elem, level) {
level = level || 0;
var $items = $elem.find("> li > a.internal, > ul, > li > ul");
// Iterate everything in order.
$items.each(function (index, item) {
var $item = $(item),
tag = item.tagName.toLowerCase(),
$childrenLi = $item.children("li"),
$parentLi = $($item.parent("li"), $item.parent().parent("li"));
// Add dropdowns if more children and above minimum level.
if (tag === "ul" && level >= minLevel && $childrenLi.length > 0) {
$parentLi
.addClass("dropdown-submenu")
.children("a").first().attr("tabindex", -1);
$item.addClass("dropdown-menu");
}
findA($item, level + 1);
});
};
findA($ul);
};
/**
* Patch all tables to remove ``docutils`` class and add Bootstrap base
* ``table`` class.
*/
patchTables = function () {
$("table.docutils")
.removeClass("docutils")
.addClass("table")
.attr("border", 0);
};
$(window).load(function () {
/*
* Scroll the window to avoid the topnav bar
* https://github.com/twbs/bootstrap/issues/1768
if ($("#navbar.navbar-fixed-top").length > 0) {
var navHeight = $("#navbar").height(),
shiftWindow = function() { scrollBy(0, -navHeight - 10); };
if (location.hash) {
setTimeout(shiftWindow, 1);
}
window.addEventListener("hashchange", shiftWindow);
}
*/
});
$(document).ready(function () {
// Add styling, structure to TOC"s.
$(".dropdown-menu").each(function () {
$(this).find("ul").each(function (index, item){
var $item = $(item);
$item.addClass("unstyled");
});
});
// Global TOC.
if ($("ul.globaltoc li").length) {
patchToc($("ul.globaltoc"), 1);
} else {
// Remove Global TOC.
$(".globaltoc-container").remove();
}
// Local TOC.
$(".bs-sidenav ul").addClass("nav nav-list");
$(".bs-sidenav > ul > li > a").addClass("nav-header");
// back to top
setTimeout(function () {
var $sideBar = $(".bs-sidenav");
var $content = $(".content");
// Enlarge content if sidebar is larger.
if ($sideBar.outerHeight(true) > $content.outerHeight(true)) {
$content.css("min-height", $sideBar.outerHeight(true));
}
$sideBar
// Add affix.
.affix({
offset: {
top: function () {
var offsetTop = $sideBar.offset().top;
var sideBarMargin = parseInt($sideBar.css("margin-top"), 10);
var navOuterHeight = $("#navbar").outerHeight(true);
return (this.top = offsetTop - navOuterHeight);
},
bottom: function () {
return (this.bottom = $(".footer").outerHeight(true));
}
}
})
// Trigger to reset if page content is scrolled to bottom.
.trigger("scroll.bs.affix.data-api");
}, 0);
// Local TOC.
patchToc($("ul.localtoc"), 2);
// Mutate sub-lists (for bs-2.3.0).
$(".dropdown-menu ul").not(".dropdown-menu").each(function () {
var $ul = $(this),
$parent = $ul.parent(),
tag = $parent[0].tagName.toLowerCase(),
$kids = $ul.children().detach();
// Replace list with items if submenu header.
if (tag === "ul") {
$ul.replaceWith($kids);
} else if (tag === "li") {
// Insert into previous list.
$parent.after($kids);
$ul.remove();
}
});
// Add divider in page TOC.
$localLi = $("ul.localtoc li");
if ($localLi.length > 2) {
$localLi.first().after("<li class=\"divider\"></li>");
}
// Patch tables.
patchTables();
// Add Note, Warning styles. (BS v2,3 compatible).
$(".admonition").addClass("alert alert-info")
.filter(".warning, .caution")
.removeClass("alert-info")
.addClass("alert-warning").end()
.filter(".error, .danger")
.removeClass("alert-info")
.addClass("alert-danger alert-error").end();
// Inline code styles to Bootstrap style.
$("tt.docutils.literal").not(".xref").each(function (i, e) {
// ignore references
if (!$(e).parent().hasClass("reference")) {
$(e).replaceWith(function () {
return $("<code />").html($(this).html());
});
}});
// Update sourcelink to remove outerdiv (fixes appearance in navbar).
var $srcLink = $(".nav #sourcelink");
$srcLink.parent().html($srcLink.html());
});
}(window.$jqTheme || window.jQuery));
\ No newline at end of file
This diff could not be displayed because it is too large.
$(document).ready(function () {
function label(lbl) {
return lbl.replace(/[ .]/g, '-').toLowerCase();
}
function showContent() {
$('.opt-group .opt').each(function(){
$('.'+label($(this).text())).hide();
$('.highlight-'+label($(this).text())).hide();
});
$('.opt-group .active').each(function(){
$('.'+label($(this).text())).show();
$('.highlight-'+label($(this).text())).show();
});
}
showContent();
function setContent() {
var el = $(this);
el.siblings().removeClass('active');
el.addClass('active');
showContent();
}
$('.opt-group').on('click', '.opt', setContent);
});
\ No newline at end of file
$(document).ready(function () {
function addToggle(tocClass) {
// Add Title
$(tocClass + " div.sphinxsidebarwrapper").prepend("<h3>Contents</h3>");
var allEntry = $(tocClass + " div.sphinxsidebarwrapper li");
var L1Entry = $(tocClass + " div.sphinxsidebarwrapper").children("ul").first().children("li");
allEntry.each(function () {
$(this).prepend("<span class='tocToggle'></span>");
var childUL = $(this).find("ul");
if (childUL.length && childUL.first().children().length) {
// $(this).addClass('closed');
// $(this).find("ul").first().hide();
} else {
$(this).addClass("leaf");
}
var anchor = $(this).children("a").first();
anchor.click(function() {toggle(anchor); autoExpand(anchor);});
});
// toctree-l1
L1Entry.each(function () {
$(this).removeClass("leaf").addClass('closed');
$(this).find("ul").first().show();
}
)
};
toggle = function(elem) {
if ($(elem).parent().hasClass("closed")) {
$(elem).parent().find("ul").first().show();
$(elem).parent().removeClass("closed").addClass("opened");
} else if ($(elem).parent().hasClass("opened")) {
$(elem).parent().find("ul").first().hide();
$(elem).parent().removeClass("opened").addClass("closed");
} else {
}
}
function autoExpand(elem) {
if (elem.parent().hasClass("closed")) {
elem.parent().removeClass("closed").addClass("opened");
elem.parent().children("ul").first().show();
} else if (elem.parent().hasClass("opened")) {
elem.parent().removeClass("opened").addClass("closed");
elem.parent().children("ul").first().hide();
} else {
}
}
function keepExpand() {
var url = window.location.href, currentEntry;
var entryList = $('.sphinxsidebar li');
for(var i = entryList.length - 1; i >= 0; --i) {
var entryURL = entryList.eq(i).find('a').first().attr('href');
if (entryURL == '#') {
currentEntry = entryList.eq(i);
break;
}
}
var allEntry = $(".leftsidebar div.sphinxsidebarwrapper li");
allEntry.each(function () {
var anchor = $(this).children("a").first();
anchor.click(function () { autoExpand(anchor); });
});
if (!currentEntry.hasClass('leaf')) currentEntry.removeClass("closed").addClass("opened");
else currentEntry.removeClass("opened").addClass("focused");
while(currentEntry.parent().is('ul') && currentEntry.parent().parent().is('li')) {
currentEntry = currentEntry.parent().parent();
xx = currentEntry.parent().children('li');
xx.each(function () {$(this).removeClass('leaf').addClass('closed');});
currentEntry.removeClass("closed").addClass("opened");
currentEntry.children("ul").first().show();
}
}
addToggle(".leftsidebar");
keepExpand()
});
\ No newline at end of file
{% extends "basic/layout.html" %}
<!----------------------- Defines ----------------------->
{% if theme_bootstrap_version == "3" %}
{% set bootstrap_version, navbar_version = "3.3.7", "" %}
{% set bs_span_prefix = "col-md-" %}
{% else %}
{% set bootstrap_version, navbar_version = "2.3.2", "-2" %}
{% set bs_span_prefix = "span" %}
{% endif %}
{%- set render_sidebar = (not embedded) and (not theme_nosidebar|tobool) and sidebars %}
{%- set bs_content_width = render_sidebar and "9" or "12"%}
<!----------------------- CSS/JS ----------------------->
{% set css_files = css_files + [
'_static/css/dragon.css',
'_static/fonts/font-awesome/css/font-awesome.min.css',
'_static/fonts/lato/css/latofonts.css'
]
%}
{% set script_files = script_files + [
'_static/js/jquery-1.11.0.min.js',
'_static/js/jquery-fix.js',
'_static/bootstrap-' + bootstrap_version + '/js/bootstrap.min.js',
'_static/js/bootstrap-sphinx.js',
]
%}
{%- if render_sidebar %}
{% set script_files = script_files + ['_static/js/sidebar.js']%}
{%- endif %}
<!----------------------- Macros ----------------------->
{%- macro bsidebar() %}
{%- if render_sidebar %}
<div class="sphinxsidebar leftsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
{%- block sidebartoc %}
{%- include "localtoc.html" %}
{%- endblock %}
</div>
</div>
{%- endif %}
{%- endmacro %}
<!----------------------- Blocks ----------------------->
{%- block doctype -%}
<!DOCTYPE html>
{%- endblock %}
{%- block extrahead %}
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1'>
<meta name="apple-mobile-web-app-capable" content="yes">
{% endblock %}
{# Silence the sidebar's, relbar's #}
{% block header %}{% endblock %}
{% block relbar1 %}{% endblock %}
{% block relbar2 %}{% endblock %}
{% block sidebarsourcelink %}{% endblock %}
{% block content %}
{% include "navbar.html" %}
<div class="container doc-container">
<div class="row">
{% block sidebar1 %}{{ bsidebar() }}{% endblock %}
<div class="content">
{% block body %}{% endblock %}
</div>
</div>
</div>
{% endblock %}
{{ toctree(maxdepth=theme_globaltoc_depth|toint, collapse=True,includehidden=theme_globaltoc_includehidden|tobool) }}
\ No newline at end of file
{# Import the theme's layout. #}
<div id="navbar" class="{{ theme_navbar_class }} navbar-default {% if theme_navbar_fixed_top|tobool -%} navbar-fixed-top{%- endif -%}">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{{ pathto("../../index") }}">
{%- block sidebarlogo %}
{%- if logo %}<span><img src="{{ pathto('_static/images/' + logo, 1) }}"></span>{%- endif %}
{%- endblock %}
{% if theme_navbar_title -%}{{ theme_navbar_title|e }}{%- else -%}{{ project|e }}{%- endif -%}
</a>
</div>
<div class="collapse navbar-collapse nav-collapse">
<ul class="nav navbar-nav">
<!-- Install -->
<li><a href="{{ pathto("../../helper/install") }}">Install</a></li>
<!-- Github -->
<li><a href="https://github.com/seetaresearch/Dragon">Github</a></li>
<!-- API -->
<li class="dropdown globaltoc-container">
<a role="button" id="dLabelGlobalToc" data-toggle="dropdown" data-target="#" href="#" aria-expanded="true">API<b class="caret"></b></a>
<ul class="dropdown-menu globaltoc" role="menu" aria-labelledby="dLabelGlobalToc">
<li class="toctree-l1 dropdown-submenu"><a class="reference internal" href="../cpp/index.html" tabindex="-1">C++</a><li>
<li class="toctree-l1 dropdown-submenu"><a class="reference internal" href="{{ pathto(master_doc) }}" tabindex="-1">Python</a><li>
</ul>
</li>
</ul>
{% block navbarsearch %}
{% include "navbarsearchbox.html" %}
{% endblock %}
</div>
</div>
</div>
{%- extends "layout.html" %}
{% if theme_bootstrap_version == "3" %}
{% set bootstrap_version, navbar_version = "3.3.7", "" %}
{% set bs_span_prefix = "col-md-" %}
{% else %}
{% set bootstrap_version, navbar_version = "2.3.2", "-2" %}
{% set bs_span_prefix = "span" %}
{% endif %}
{%- set render_sidebar = False %}
{% set title = _('Search') %}
{% set script_files = script_files + ['_static/searchtools.js'] %}
{% block extrahead %}
<script type="text/javascript" xmlns="http://www.w3.org/1999/html">
jQuery(function () { Search.loadIndex("{{ pathto('searchindex.js', 1) }}"); });
</script>
{# this is used when loading the search index using $.ajax fails,
such as on Chrome for documents on localhost #}
<script type="text/javascript" id="searchindexloader"></script>
{{ super() }}
{% endblock %}
{% block content %}
{% include "navbar.html" %}
<div class="container doc-container">
<div class="col-lg-2"></div>
<div class="col-lg-8">
{% block sidebar1 %}{{ bsidebar() }}{% endblock %}
<div class="content" style="width: 100%">
<h1 id="search-documentation">{{ _('Search') }}</h1>
<div id="fallback" class="admonition warning">
<script type="text/javascript">$('#fallback').hide();</script>
<p>
{% trans %}Please activate JavaScript to enable the search
functionality.{% endtrans %}
</p>
</div>
<p>
From here you can search these documents. Enter your search words into the box below and click <strong>Search</strong>.
</p>
{% if theme_bootstrap_version == "3" %}
<form class="form-inline" action="" method="get">
<div class="form-group">
<input type="text" class="form-control" name="q" value="" />
</div>
<input type="submit" class="btn btn-default" value="Search" />
<span id="search-progress" style="padding-left: 10px"></span>
</form>
{% else %}
<form class="form-search">
<input type="text" class="input-medium search-query" name="q" value="" />
<input type="submit" class="btn btn-default" value="{{ _('search') }}" />
<span id="search-progress" style="padding-left: 10px"></span>
</form>
{% endif %}
{% if search_performed %}
<h2>{{ _('Search Results') }}</h2>
{% if not search_results %}
<p>{{ _('Your search did not match any documents. Please make sure that all words are spelled correctly and that you\'ve selected enough categories.') }}</p>
{% endif %}
{% endif %}
<div id="search-results">
{% if search_results %}
<ul>
{% for href, caption, context in search_results %}
<li>
<a href="{{ pathto(item.href) }}">{{ caption }}</a>
<div class="context">{{ context|e }}</div>
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
</div>
<div class="col-lg-2"></div>
</div>
{% endblock %}
# ------------------------------------------------------------
# Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
#
# Licensed under the BSD 2-Clause License.
# You should have received a copy of the BSD 2-Clause License
# along with the software. If not, See,
#
# <https://opensource.org/licenses/BSD-2-Clause>
#
# ------------------------------------------------------------
import sys
import os
import sphinx_bootstrap_theme
# basic
html_static_path = ['_static']
templates_path = ['_templates']
exclude_patterns = ['_build']
source_suffix = '.rst'
master_doc = 'index'
pygments_style = 'sphinx'
todo_include_todos = True
# extensions
sys.path.insert(0, os.path.abspath('_extensions'))
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinx.ext.napoleon',
#'sphinx.ext.viewcode',
'mathmacro',
]
# project
project = ''
copyright = '2017, Ting Pan'
author = 'Ting Pan'
html_logo = "dragon.png"
html_title = ""
html_short_title = ""
html_favicon = 'images/favicon.png'
version = ''
release = ''
language = None
# theme
html_theme = 'bootstrap'
html_theme_path = sphinx_bootstrap_theme.get_html_theme_path()
html_show_sourcelink = False
html_show_sphinx = False
html_show_copyright = False
html_theme_options = {
'globaltoc_depth': -1,
'navbar_class': "navbar navbar-inverse",
'navbar_fixed_top': "true",
'bootswatch_theme': "yeti",
}
html_sidebars = {'index': ['localtoc.html'],
'install': ['localtoc.html'],
'contents/**': ['localtoc.html']}
# overloads
def setup(app):
app.config.values['autodoc_member_order'] = ('bysource', True)
====================
:mod:`dragon.config`
====================
.. toctree::
:hidden:
Quick Reference
---------------
=============================== =============================================================================
List Brief
=============================== =============================================================================
`EnableCPU`_ Enable CPU mode globally.
`EnableCUDA`_ Enable CUDA mode globally.
`SetRandomSeed`_ Set the global random seed.
`GetRandomSeed`_ Get the global random seed.
`SetGPU`_ Set the global id GPU.
`GetGPU`_ Get the global id of GPU.
`SetGraphOptimizationLevel`_ Set the default level of graph optimization.
`LogMetaGraph`_ Enable to log meta graph globally.
`LogOptimizedGraph`_ Enable to log optimized graph globally.
`ExportMetaGraph`_ Enable to export all runnable meta graphs into text files.
`SetLoggingLevel`_ Set the minimum level of Logging.
`SetLoggingFile`_ Redirect the logging into the specific file.
=============================== =============================================================================
API Reference
-------------
.. automodule:: dragon.config
:members:
.. _EnableCPU: #dragon.config.EnableCPU
.. _EnableCUDA: #dragon.config.EnableCUDA
.. _SetRandomSeed: #dragon.config.SetRandomSeed
.. _GetRandomSeed: #dragon.config.GetRandomSeed
.. _SetGPU: #dragon.config.SetGPU
.. _GetGPU: #dragon.config.GetGPU
.. _SetGraphOptimizationLevel: #dragon.config.SetGraphOptimizationLevel
.. _LogMetaGraph: #dragon.config.LogMetaGraph
.. _LogOptimizedGraph: #dragon.config.LogOptimizedGraph
.. _ExportMetaGraph: #dragon.config.ExportMetaGraph
.. _SetLoggingLevel: #dragon.config.SetLoggingLevel
.. _SetLoggingFile: #dragon.config.SetLoggingFile
\ No newline at end of file
==================
:mod:`dragon.core`
==================
Data Structure
--------------
.. toctree::
:hidden:
core/tensor
core/scope
============================== =======================================================================
List Brief
============================== =======================================================================
`dragon.core.scope`_ The Scope and Namespace.
`dragon.core.tensor`_ The basic structure of VM.
============================== =======================================================================
C++ Binding Wrapper
-------------------
.. toctree::
:hidden:
core/workspace
core/tensor_utils
core/mpi
core/cuda
core/gradient_maker
============================== =======================================================================
List Brief
============================== =======================================================================
`dragon.core.workspace`_ The interfaces of Workspace, mostly are the wrappers of C++.
`dragon.core.gradient_maker`_ The generator of GradientOps.
`dragon.core.tensor_utils`_ List some extended Tensor C++ API.
`dragon.core.mpi`_ List some useful MPI C++ API.
`dragon.core.cuda`_ List some useful CUDA C++ API.
============================== =======================================================================
.. _dragon.core.mpi: core/mpi.html
.. _dragon.core.cuda: core/cuda.html
.. _dragon.core.scope: core/scope.html
.. _dragon.core.tensor: core/tensor.html
.. _dragon.core.tensor_utils: core/tensor_utils.html
.. _dragon.core.workspace: core/workspace.html
.. _dragon.core.gradient_maker: core/gradient_maker.html
\ No newline at end of file
===========
:mod:`CUDA`
===========
.. toctree::
:hidden:
Quick Reference
---------------
============================== =============================================================================
List Brief
============================== =============================================================================
`IsCUDADriverSufficient`_ Is cuda driver sufficient?
`EnableCUDNN`_ Enable the CuDNN engine.
`GetDevice`_ Get the current active cuda device.
`SynchronizeStream`_ Synchronize the specified cuda stream.
============================== =============================================================================
.. automodule:: dragon.core.cuda
:members:
.. _IsCUDADriverSufficient: #dragon.core.cuda.IsCUDADriverSufficient
.. _EnableCUDNN: #dragon.core.cuda.EnableCUDNN
.. _GetDevice: #dragon.core.cuda.GetDevice
.. _SynchronizeStream: #dragon.core.cuda.SynchronizeStream
\ No newline at end of file
====================
:mod:`GradientMaker`
====================
.. toctree::
:hidden:
.. currentmodule:: dragon.core.gradient_maker
.. autoclass:: GraphGradientMaker
:members:
.. _theano.function(*args, **kwargs): ../vm/theano/compile.html#dragon.vm.theano.compile.function.function
\ No newline at end of file
==========
:mod:`MPI`
==========
.. toctree::
:hidden:
Basic
-----
============================== =============================================================================
List Brief
============================== =============================================================================
`Init`_ Init the MPI env.
`Is_Init`_ Whether the MPI env has initialized.
`Rank`_ The world rank of current MPI node.
`Size`_ The world size of current MPI env.
`CreateGroup`_ Construct a MPIGroup with specific members.
`Finalize`_ Finalize the MPI env.
============================== =============================================================================
Parallelism
-----------
============================== =============================================================================
List Brief
============================== =============================================================================
`Snapshot`_ Set the specific MPI nodes to snapshot.
`Parallel`_ Set the specific MPI nodes for data parallelism.
`AllowSnapshot`_ Whether this node can snapshot.
`AllowParallel`_ Whether this node was set for data parallelism.
`SetParallelMode`_ Set the mode of data parallelism.
`GetParallelMode`_ Get the current mode of data parallelism.
============================== =============================================================================
.. automodule:: dragon.core.mpi
:members:
.. _Init: #dragon.core.mpi.Init
.. _Is_Init: #dragon.core.mpi.Is_Init
.. _Rank: #dragon.core.mpi.Rank
.. _Size: #dragon.core.mpi.Size
.. _CreateGroup: #dragon.core.mpi.CreateGroup
.. _Finalize: #dragon.core.mpi.Finalize
.. _Snapshot: #dragon.core.mpi.Snapshot
.. _Parallel: #dragon.core.mpi.Parallel
.. _AllowSnapshot: #dragon.core.mpi.AllowSnapshot
.. _AllowParallel: #dragon.core.mpi.AllowParallel
.. _SetParallelMode: #dragon.core.mpi.SetParallelMode
.. _GetParallelMode: #dragon.core.mpi.GetParallelMode
.. _workspace.Snapshot(*args, **kwargs): workspace.html#dragon.core.workspace.Snapshot
\ No newline at end of file
============
:mod:`Scope`
============
.. toctree::
:hidden:
.. automodule:: dragon.core.scope
:members:
\ No newline at end of file
=============
:mod:`Tensor`
=============
.. toctree::
:hidden:
Quick Reference
---------------
============================== =============================================================================
List Brief
============================== =============================================================================
`Tensor.name`_ Return or Set the name.
`Tensor.shape`_ Return or Set the shape.
`Tensor.get_shape`_ Return the shape.
`Tensor.dtype`_ Return or Set the data type.
`Tensor.set_value`_ Feed the values to C++ backend.
`Tensor.get_value`_ Fetch the values from C++ backend.
`Tensor.convert_to`_ Converts the given value to a Tensor.
`Tensor.copy`_ Return a Tensor with same content.
`Tensor.reshape`_ Reshape the dimensions of input.
`Tensor.dimshuffle`_ Shuffle the dimensions.
`Tensor.eval`_ Run and return the computing results of this tensor.
============================== =============================================================================
Register
--------
============================== =============================================================================
List Brief
============================== =============================================================================
`Tensor.Variable`_ Register as an empty variable.
`Tensor.Placeholder`_ Register as a placeholder.
`Tensor.Constant`_ Register as a variable with constant initializer.
`Tensor.Uniform`_ Register as a variable with uniform initializer.
`Tensor.Normal`_ Register as a variable with normal initializer.
`Tensor.TruncatedNormal`_ Register as a variable with truncated normal initializer.
`Tensor.Gaussian`_ Register as a variable with gaussian initializer.
`Tensor.GlorotUniform`_ Register as a variable with glorot uniform initializer.
`Tensor.GlorotNormal`_ Register as a variable with glorot normal initializer.
============================== =============================================================================
Override
--------
============================== =============================================================================
List Brief
============================== =============================================================================
`Tensor.__add__`_ x.__add__(y) <=> x + y
`Tensor.__radd__`_ x.__radd__(y) <=> y + x
`Tensor.__sub__`_ x.__sub__(y) <=> x - y
`Tensor.__rsub__`_ x.__rsub__(y) <=> y - x
`Tensor.__mul__`_ x.__mul__(y) <=> x * y
`Tensor.__rmul__`_ x.__rmul__(y) <=> y * x
`Tensor.__div__`_ x.__div__(y) <=> x / y
`Tensor.__rdiv__`_ x.__rdiv__(y) <=> y / x
`Tensor.__neg__`_ x.__neg__() <=> -x
`Tensor.__gt__`_ x.__gt__() <=> x > y
`Tensor.__ge__`_ x.__ge__() <=> x >= y
`Tensor.__lt__`_ x.__lt__() <=> x < y
`Tensor.__le__`_ x.__le__() <=> x <= y
`Tensor.__eq__`_ x.__eq__() <=> x == y
`Tensor.__repr__`_ Return the information(name/shape).
`Tensor.__getitem__`_ Return the value at the specific indices.
`Tensor.__setitem__`_ Set the value at the specific indices.
============================== =============================================================================
API Reference
-------------
.. currentmodule:: dragon.core.tensor
.. autoclass:: Tensor
:members:
.. automethod:: __init__
.. automethod:: __add__
.. automethod:: __radd__
.. automethod:: __sub__
.. automethod:: __rsub__
.. automethod:: __mul__
.. automethod:: __rmul__
.. automethod:: __div__
.. automethod:: __rdiv__
.. automethod:: __neg__
.. automethod:: __gt__
.. automethod:: __ge__
.. automethod:: __lt__
.. automethod:: __le__
.. automethod:: __eq__
.. automethod:: __eq__
.. automethod:: __repr__
.. automethod:: __getitem__
.. automethod:: __setitem__
.. _Tensor.Variable: #dragon.core.tensor.Tensor.Variable
.. _Tensor.Placeholder: #dragon.core.tensor.Tensor.Placeholder
.. _Tensor.Constant: #dragon.core.tensor.Tensor.Constant
.. _Tensor.Uniform: #dragon.core.tensor.Tensor.Uniform
.. _Tensor.Normal: #dragon.core.tensor.Tensor.Normal
.. _Tensor.TruncatedNormal: #dragon.core.tensor.Tensor.TruncatedNormal
.. _Tensor.Gaussian: #dragon.core.tensor.Tensor.Gaussian
.. _Tensor.GlorotUniform: #dragon.core.tensor.Tensor.GlorotUniform
.. _Tensor.GlorotNormal: #dragon.core.tensor.Tensor.GlorotNormal
.. _Tensor.__add__: #dragon.core.tensor.Tensor.__add__
.. _Tensor.__radd__: #dragon.core.tensor.Tensor.__radd__
.. _Tensor.__sub__: #dragon.core.tensor.Tensor.__sub__
.. _Tensor.__rsub__: #dragon.core.tensor.Tensor.__rsub__
.. _Tensor.__mul__: #dragon.core.tensor.Tensor.__mul__
.. _Tensor.__rmul__: #dragon.core.tensor.Tensor.__rmul__
.. _Tensor.__div__: #dragon.core.tensor.Tensor.__div__
.. _Tensor.__rdiv__: #dragon.core.tensor.Tensor.__rdiv__
.. _Tensor.__neg__: #dragon.core.tensor.Tensor.__neg__
.. _Tensor.__gt__: #dragon.core.tensor.Tensor.__gt__
.. _Tensor.__ge__: #dragon.core.tensor.Tensor.__ge__
.. _Tensor.__lt__: #dragon.core.tensor.Tensor.__lt__
.. _Tensor.__le__: #dragon.core.tensor.Tensor.__le__
.. _Tensor.__eq__: #dragon.core.tensor.Tensor.__eq__
.. _Tensor.__repr__: #dragon.core.tensor.Tensor.__repr__
.. _Tensor.__getitem__: #dragon.core.tensor.Tensor.__getitem__
.. _Tensor.__setitem__: #dragon.core.tensor.Tensor.__setitem__
.. _Tensor.__call__: #dragon.core.tensor.Tensor.__call__
.. _Tensor.name: #dragon.core.tensor.Tensor.name
.. _Tensor.shape: #dragon.core.tensor.Tensor.shape
.. _Tensor.get_shape: #dragon.core.tensor.Tensor.get_shape
.. _Tensor.dtype: #dragon.core.tensor.Tensor.dtype
.. _Tensor.set_value: #dragon.core.tensor.Tensor.set_value
.. _Tensor.get_value: #dragon.core.tensor.Tensor.get_value
.. _Tensor.convert_to: #dragon.core.tensor.Tensor.convert_to
.. _Tensor.copy: #dragon.core.tensor.Tensor.copy
.. _Tensor.reshape: #dragon.core.tensor.Tensor.reshape
.. _Tensor.dimshuffle: #dragon.core.tensor.Tensor.dimshuffle
.. _Tensor.eval: #dragon.core.tensor.Tensor.eval
.. _workspace.FeedTensor(*args, **kwargs): workspace.html#dragon.core.workspace.FeedTensor
.. _workspace.FetchTensor(*args, **kwargs): workspace.html#dragon.core.workspace.FetchTensor
.. _ops.Copy(*args, **kwargs): ../operators/control_flow.html#dragon.operators.control_flow.Copy
==================
:mod:`TensorUtils`
==================
.. toctree::
:hidden:
Quick Reference
---------------
============================== =============================================================================
List Brief
============================== =============================================================================
`FromShape`_ Create a Tensor from the given shape.
`FromArray`_ Create a Tensor from an existing Array.
`ToArray`_ Create a Array from an existing Tensor.
`SetShape`_ Set a Tensor with the shape.
`SetArray`_ Set a Tensor from an existing Array.
`GetStorage`_ Get the storage of an existing Tensor.
============================== =============================================================================
API Reference
-------------
.. automodule:: dragon.core.tensor_utils
:members:
.. _FromShape: #dragon.core.tensor_utils.FromShape
.. _FromArray: #dragon.core.tensor_utils.FromArray
.. _ToArray: #dragon.core.tensor_utils.ToArray
.. _SetShape: #dragon.core.tensor_utils.SetShape
.. _SetArray: #dragon.core.tensor_utils.SetArray
.. _GetStorage: #dragon.core.tensor_utils.GetStorage
\ No newline at end of file
================
:mod:`Workspace`
================
.. toctree::
:hidden:
Workspace
---------
============================== =============================================================================
List Brief
============================== =============================================================================
`Workspace(object)`_ A wrapper for the C implemented workspace.
`get_default_workspace`_ Return the current default workspace.
`reset_default_workspace`_ Reset the global default workspace.
============================== =============================================================================
Tensor
------
============================== =============================================================================
List Brief
============================== =============================================================================
`HasTensor`_ Query whether tensor has registered in current workspace.
`CreateFiller`_ Create the filler in the backend.
`GetTensorName`_ Query the name represented in current workspace.
`SetTensorAlias`_ Bind a alias to a existed tensor.
`FeedTensor`_ Feed the values to the given tensor.
`FetchTensor`_ Fetch the values of given tensor.
`ResetTensor`_ Reset the memory of given tensor.
============================== =============================================================================
Operator
--------
============================== =============================================================================
List Brief
============================== =============================================================================
`RunOperator`_ Run the operator in the VM backend.
============================== =============================================================================
Graph
-----
============================== =============================================================================
List Brief
============================== =============================================================================
`CreateGraph`_ Create the graph in the backend.
`RunGraph`_ Run the specific graph.
============================== =============================================================================
I/O
---
============================== =============================================================================
List Brief
============================== =============================================================================
`Snapshot`_ Snapshot tensors into a binary file.
`Restore`_ Restore tensors from a binary file.
============================== =============================================================================
API Reference
-------------
.. automodule:: dragon.core.workspace
:members:
:undoc-members:
.. autoclass:: Workspace
:members:
.. automethod:: __init__
.. _Workspace(object): #dragon.core.workspace.Workspace
.. _get_default_workspace: #dragon.core.workspace.get_default_workspace
.. _reset_default_workspace: #dragon.core.workspace.reset_default_workspace
.. _CreateGraph: #dragon.core.workspace.CreateGraph
.. _HasTensor: #dragon.core.workspace.HasTensor
.. _GetTensorName: #dragon.core.workspace.GetTensorName
.. _SetTensorAlias: #dragon.core.workspace.SetTensorAlias
.. _CreateFiller: #dragon.core.workspace.CreateFiller
.. _FetchTensor: #dragon.core.workspace.FetchTensor
.. _FeedTensor: #dragon.core.workspace.FeedTensor
.. _ResetTensor: #dragon.core.workspace.ResetTensor
.. _RunOperator: #dragon.core.workspace.RunOperator
.. _RunGraph: #dragon.core.workspace.RunGraph
.. _Snapshot: #dragon.core.workspace.Snapshot
.. _Restore: #dragon.core.workspace.Restore
.. _theano.function(*args, **kwargs): ../vm/theano/compile.html#dragon.vm.theano.compile.function.function
\ No newline at end of file
======================
:mod:`dragon.memonger`
======================
.. toctree::
:hidden:
Quick Reference
---------------
==================== =============================================================================
List Brief
==================== =============================================================================
`ShareGrads`_ Enable gradients sharing globally.
`Drop`_ Drop(Share) the inputs for outputs.
==================== =============================================================================
API Reference
-------------
.. automodule:: dragon.memonger
:members:
.. _ShareGrads: #dragon.memonger.ShareGrads
.. _Drop: #dragon.memonger.Drop
\ No newline at end of file
=======================
:mod:`dragon.operators`
=======================
Common
------
.. toctree::
:hidden:
operators/data
operators/initializer
operators/arithmetic
operators/array
operators/control_flow
operators/misc
operators/mpi
=================================== =====================================================================
List Brief
=================================== =====================================================================
`dragon.operators.data`_ The data preparing operators.
`dragon.operators.initializer`_ The initializing operators.
`dragon.operators.arithmetic`_ The arithmetic operators.
`dragon.operators.ndarray`_ The ndarray operators.
`dragon.operators.control_flow`_ The control flow operators.
`dragon.operators.misc`_ The misc operators.
`dragon.operators.mpi`_ The MPI operators.
=================================== =====================================================================
Neural Networks
---------------
.. toctree::
:hidden:
operators/norm
operators/activation
operators/vision
operators/recurrent
operators/loss
=================================== =====================================================================
List Brief
=================================== =====================================================================
`dragon.operators.norm`_ The normalization operators.
`dragon.operators.activation`_ The activation operators.
`dragon.operators.vision`_ The vision operators.
`dragon.operators.recurrent`_ The recurrent operators.
`dragon.operators.loss`_ The loss operators.
=================================== =====================================================================
Custom
------
.. toctree::
:hidden:
operators/custom/minibatch
========================================= =====================================================================
List Brief
========================================= =====================================================================
`dragon.operators.custom.minibatch`_ Form a mini-batch based on `dragon.utils.vision`_ package.
========================================= =====================================================================
Contrib
-------
.. toctree::
:hidden:
operators/contrib/rcnn
========================================= =====================================================================
List Brief
========================================= =====================================================================
`dragon.operators.contrib.rcnn`_ Contrib ops for R-CNN.
========================================= =====================================================================
.. _dragon.operators.data: operators/data.html
.. _dragon.operators.initializer: operators/initializer.html
.. _dragon.operators.arithmetic: operators/arithmetic.html
.. _dragon.operators.ndarray: operators/ndarray.html
.. _dragon.operators.control_flow: operators/control_flow.html
.. _dragon.operators.misc: operators/misc.html
.. _dragon.operators.mpi: operators/mpi.html
.. _dragon.operators.activation: operators/activation.html
.. _dragon.operators.vision: operators/vision.html
.. _dragon.operators.recurrent: operators/recurrent.html
.. _dragon.operators.loss: operators/loss.html
.. _dragon.operators.norm: operators/norm.html
.. _dragon.operators.custom.minibatch: operators/custom/minibatch.html
.. _dragon.operators.custom.data_process: operators/custom/data_process.html
.. _dragon.operators.custom.vec_mult: operators/custom/vec_mult.html
.. _dragon.operators.contrib.rcnn: operators/contrib/rcnn.html
.. _dragon.utils.vision: utils.html#vision
=================
:mod:`Activation`
=================
.. toctree::
:hidden:
.. automodule:: dragon.operators.activation
:members:
.. |sigmoid_function| mathmacro:: \, y = \frac{1}{1 + {e}^{-x}}
.. |tanh_function| mathmacro:: \, y = \frac{e^{x} - e^{-x}}{e^{x} + e^{-x}}
.. |relu_function| mathmacro:: \, y = \left\{ \begin{array} \\ x & & (x > 0) \\ 0 & & (x <= 0) \\ \end{array} \right.
.. |lrelu_function| mathmacro:: \, y = \left\{ \begin{array} \\ x & & (x > 0) \\ Slope * x & & (x <= 0) \\ \end{array} \right.
.. |prelu_function| mathmacro:: \, y_{i} = \left\{ \begin{array} \\ x_{i} & & (x_{i} > 0) \\ \alpha_{i} * x_{i} & & (x <= 0) \\ \end{array} \right.
.. |elu_function| mathmacro:: \, y = \left\{ \begin{array} \\ x & & (x > 0) \\ Alpha * (e^{x} - 1) & & (x <= 0) \\ \end{array} \right.
.. |selu_function| mathmacro:: \, y = 1.0507 \left\{ \begin{array} \\ x & & (x > 0) \\ 1.6733 * (e^{x} - 1) & & (x <= 0) \\ \end{array} \right.
.. |dropout_function| mathmacro:: \, y = x * Bernoulli(p=1 - prob)
.. |softmax_function| mathmacro:: \, y = \frac{e^{x_{i}}}{\sum e^{x_{j}}}
=================
:mod:`Arithmetic`
=================
.. toctree::
:hidden:
.. automodule:: dragon.operators.arithmetic
:members:
.. |power_function| mathmacro:: \\ \, y = [(Scale * x) + Shift]^{Power}
.. |scale_function| mathmacro:: \\ [Axis, Axis + NumAxes)
.. |gram_matrix_function| mathmacro:: \\ \, y = xx^{T}
\ No newline at end of file
============
:mod:`Array`
============
.. toctree::
:hidden:
.. automodule:: dragon.operators.array
:members:
.. _ops.Reduce(*args, **kwargs): #dragon.operators.array.Reduce
\ No newline at end of file
============
:mod:`R-CNN`
============
.. toctree::
:hidden:
.. automodule:: dragon.operators.contrib.rcnn.ops
:members:
\ No newline at end of file
===================
:mod:`Control Flow`
===================
.. toctree::
:hidden:
.. automodule:: dragon.operators.control_flow
:members:
\ No newline at end of file
================
:mod:`MiniBatch`
================
.. toctree::
:hidden:
.. currentmodule:: dragon.operators.custom.minibatch
.. autoclass:: MiniBatchOp
:members:
.. _dragon.utils.vision: ../../utils.html#vision
\ No newline at end of file
===========
:mod:`Data`
===========
.. toctree::
:hidden:
.. automodule:: dragon.operators.data
:members:
.. _LMDB: http://lmdb.readthedocs.io/en/release
.. _DataBatch: ../utils/vision/data_batch.html
.. _DataReader: ../utils/vision/data_reader.html
.. _DataTransformer: ../utils/vision/data_transformer.html
.. _BlobFetcher: ../utils/vision/blob_fetcher.html
\ No newline at end of file
==================
:mod:`Initializer`
==================
.. toctree::
:hidden:
.. automodule:: dragon.operators.initializer
:members:
.. |glorot_uniform_bounds| mathmacro:: \\ (-\sqrt{\frac{Scale}{Fan}}, \sqrt{\frac{Scale}{Fan}})
.. |glorot_normal_parameters| mathmacro:: \\ (\mu = 0, \sigma = \sqrt{\frac{Scale}{Fan}})
.. |truncated_normal_bounds| mathmacro:: \\ (\mu - 2\sigma, \mu + 2\sigma)
===========
:mod:`Loss`
===========
.. toctree::
:hidden:
.. automodule:: dragon.operators.loss
:members:
.. |smooth_l1_beta| mathmacro:: \, \frac{1}{\sigma^{2}}
.. |l1_loss_function| mathmacro:: \, Loss = \frac{ \sum \left| Weight * (Input - Target) \right|}{ Normalization}
.. |l2_loss_function| mathmacro:: \, Loss = \frac{ \sum \frac{1}{2}\left|\left| Weight * (Input - Target) \right|\right|}{ Normalization}
\ No newline at end of file
===========
:mod:`Misc`
===========
.. toctree::
:hidden:
.. automodule:: dragon.operators.misc
:members:
.. _Template(*args, **kwargs): #dragon.operators.misc.Template
.. _DataProcessOp: custom/data_process.html
.. _VecMultOp: custom/vec_mult.html
.. |moving_average_function| mathmacro:: \\ \, \\ Variable = Decay * Variable + (1 - decay) * Value
\ No newline at end of file
==========
:mod:`MPI`
==========
.. toctree::
:hidden:
.. automodule:: dragon.operators.mpi
:members:
\ No newline at end of file
====================
:mod:`Normalization`
====================
.. toctree::
:hidden:
.. automodule:: dragon.operators.norm
:members:
.. |batchnorm_function| mathmacro:: \\ \, \\ \mu_{B} = \frac{1}{m} \sum_{i=1}^{m}x_{i} \\
\sigma_{B}^{2} = \frac{1}{m} \sum_{i=1}^{m}(x_{i} - \mu_{B})^{2} \\
\hat{x}_{i} = \frac{x_{i} - \mu_{B}}{\sqrt{\sigma_{B}^{2} + \epsilon}} \\ \,
.. |batchnorm_scale_function| mathmacro:: \\ \, \\ \mu_{B} = \frac{1}{m} \sum_{i=1}^{m}x_{i} \\
\sigma_{B}^{2} = \frac{1}{m} \sum_{i=1}^{m}(x_{i} - \mu_{B})^{2} \\
\hat{x}_{i} = \frac{x_{i} - \mu_{B}}{\sqrt{\sigma_{B}^{2} + \epsilon}} \\ y_{i} = \gamma\hat{x}_{i} + \beta \\ \,
.. |groupnorm_function| mathmacro:: \\ \, \\ \mu_{G} = \frac{1}{m} \sum_{i=1}^{m}x_{i} \\
\sigma_{G}^{2} = \frac{1}{m} \sum_{i=1}^{m}(x_{i} - \mu_{G})^{2} \\
\hat{x}_{i} = \frac{x_{i} - \mu_{G}}{\sqrt{\sigma_{G}^{2} + \epsilon}} \\ \,
.. |groupnorm_scale_function| mathmacro:: \\ \, \\ \mu_{G} = \frac{1}{m} \sum_{i=1}^{m}x_{i} \\
\sigma_{G}^{2} = \frac{1}{m} \sum_{i=1}^{m}(x_{i} - \mu_{G})^{2} \\
\hat{x}_{i} = \frac{x_{i} - \mu_{G}}{\sqrt{\sigma_{G}^{2} + \epsilon}} \\ y_{i} = \gamma\hat{x}_{i} + \beta \\ \,
.. |batchrenorm_function| mathmacro:: \\ \, \\ \mu_{B} = \frac{1}{m} \sum_{i=1}^{m}x_{i} \\
\sigma_{B}^{2} = \frac{1}{m} \sum_{i=1}^{m}(x_{i} - \mu_{B})^{2} \\
\hat{x}_{i} = \frac{x_{i} - \mu_{B}}{\sqrt{\sigma_{B}^{2} + \epsilon}} \cdot r + d \\ \,
.. |default_moving_average_function| mathmacro:: \\ \, \\ x_{moving} \leftarrow Momentum * x_{moving} + (1 - Momentum) * x_{stat} \\ \,
.. |caffe_moving_average_function| mathmacro:: \\ \, \\ x_{moving} \leftarrow Momentum * x_{moving} + x_{stat} \\ \,
.. _ops.Affine(*args, **kwargs): arithmetic.html#dragon.operators.arithmetic.Affine
.. _Caffe: https://github.com/BVLC/caffe/
================
:mod:`Recurrent`
================
.. toctree::
:hidden:
.. currentmodule:: dragon.operators.recurrent
.. autoclass:: RNN
:members:
.. automethod:: __init__
.. autoclass:: LSTM
:members:
.. automethod:: __init__
.. autoclass:: GRU
:members:
.. automethod:: __init__
.. autofunction:: dragon.operators.recurrent.LSTMCell
\ No newline at end of file
=============
:mod:`Vision`
=============
.. toctree::
:hidden:
.. automodule:: dragon.operators.vision
:members:
.. |conv_output_dim| mathmacro:: \\ DilatedKernelSize = Dilation * (KernelSize - 1) + 1 \\
OutputDim = (InputDim + 2 * Pad - DilatedKernelSize) / Stride + 1
.. |deconv_output_dim| mathmacro:: \\ DilatedKernelSize = Dilation * (KernelSize - 1) + 1 \\
OutputDim = Stride * (InputDim - 1) + DilatedKernelSize - 2 * Pad
.. |pooling_output_dim| mathmacro:: \\ OutputDim = Ceil((InputDim + 2 * Pad - KernelSize) / Stride) + 1
\ No newline at end of file
===================
:mod:`dragon.tools`
===================
Overview
--------
|para| In this section, we will introduce several tools for flexible tasks of Deep Learning.
|para| Those tools are based on the existing python packages,
which are easy to install(by `pip`_) and can adapt to all os platforms. We will never rebuild them
in the C++ backend because they could make our kernels dirty and messy(especially the **Sequential Databases**).
ToolBox
-------
.. toctree::
:hidden:
tools/db
tools/tensorboard
==================== ====================================================================================
List Brief
==================== ====================================================================================
`LMDB`_ A wrapper of LMDB package.
`TensorBoard`_ Write summaries for TensorBoard.
==================== ====================================================================================
.. |para| raw:: html
<p style="text-indent:1.5em; font-size: 18px; max-width: 830px;">
.. _pip: https://pypi.python.org/pypi/pip
.. _LMDB: tools/db.html
.. _TensorBoard: tools/tensorboard.html
===========
:mod:`LMDB`
===========
.. toctree::
:hidden:
Quick Reference
---------------
==================== =============================================================================
List Brief
==================== =============================================================================
`LMDB.open`_ Open the database.
`LMDB.put`_ Put the item.
`LMDB.commit`_ Commit all items that have been put.
`LMDB.set`_ Set the cursor to the specific key.
`LMDB.get`_ Get the value of the specific key.
`LMDB.next`_ Set the cursor to the next.
`LMDB.key`_ Get the key under the current cursor.
`LMDB.value`_ Get the value under the current cursor.
`LMDB.close`_ Close the database.
==================== =============================================================================
API Reference
-------------
.. currentmodule:: dragon.tools.db
.. autoclass:: LMDB
:members:
.. automethod:: __init__
.. _LMDB.open: #dragon.tools.db.LMDB.open
.. _LMDB.put: #dragon.tools.db.LMDB.put
.. _LMDB.commit: #dragon.tools.db.LMDB.commit
.. _LMDB.set: #dragon.tools.db.LMDB.set
.. _LMDB.get: #dragon.tools.db.LMDB.get
.. _LMDB.next: #dragon.tools.db.LMDB.next
.. _LMDB.key: #dragon.tools.db.LMDB.key
.. _LMDB.value: #dragon.tools.db.LMDB.value
.. _LMDB.close: #dragon.tools.db.LMDB.close
\ No newline at end of file
==================
:mod:`TensorBoard`
==================
.. toctree::
:hidden:
Quick Reference
---------------
==================== =============================================================================
List Brief
==================== =============================================================================
`scalar_summary`_ Write a scalar variable.
`histogram_summary`_ Write a histogram of values.
`image_summary`_ Write a list of images.
`close`_ Close the board and apply all cached summaries.
==================== =============================================================================
API Reference
-------------
.. currentmodule:: dragon.tools.tensorboard
.. autoclass:: TensorBoard
:members:
.. automethod:: __init__
.. _scalar_summary: tensorboard.html#dragon.tools.tensorboard.TensorBoard.scalar_summary
.. _histogram_summary: tensorboard.html#dragon.tools.tensorboard.TensorBoard.histogram_summary
.. _image_summary: tensorboard.html#dragon.tools.tensorboard.TensorBoard.image_summary
.. _close: tensorboard.html#dragon.tools.tensorboard.TensorBoard.close
======================
:mod:`dragon.updaters`
======================
.. toctree::
:hidden:
Quick Reference
---------------
==================== =============================================================================
List Brief
==================== =============================================================================
`SGDUpdater`_ The Momentum-SGD Updater, introduced by `[LeCun et.al, 1998]`_.
`NesterovUpdater`_ The Nesterov-SGD Updater, introduced by `[Sutskever et.al, 2012]`_.
`RMSPropUpdater`_ The RMSProp Updater, introduced by `[Hinton et.al, 2013]`_.
`AdamUpdater`_ The Adam Updater, introduced by `[Kingma & Ba, 2014]`_.
==================== =============================================================================
API Reference
-------------
.. currentmodule:: dragon.updaters
.. autoclass:: BaseUpdater
:members:
.. automethod:: __init__
.. autoclass:: SGDUpdater
:members:
.. automethod:: __init__
.. autoclass:: NesterovUpdater
:members:
.. automethod:: __init__
.. autoclass:: RMSPropUpdater
:members:
.. automethod:: __init__
.. autoclass:: AdamUpdater
:members:
.. automethod:: __init__
.. _[LeCun et.al, 1998]: http://yann.lecun.com/exdb/publis/#lecun-98b
.. _[Sutskever et.al, 2012]: http://www.cs.utoronto.ca/~bonner/courses/2016s/csc321/lectures/lec6.pdf
.. _[Hinton et.al, 2013]: http://www.cs.utoronto.ca/~bonner/courses/2016s/csc321/lectures/lec6.pdf
.. _[Kingma & Ba, 2014]: https://arxiv.org/abs/1412.6980
.. _SGDUpdater: #dragon.updaters.SGDUpdater
.. _NesterovUpdater: #dragon.updaters.NesterovUpdater
.. _RMSPropUpdater: #dragon.updaters.RMSPropUpdater
.. _AdamUpdater: #dragon.updaters.AdamUpdater
\ No newline at end of file
===================
:mod:`dragon.utils`
===================
Vision
------
.. toctree::
:hidden:
utils/vision/database
utils/vision/data_batch
utils/vision/data_reader
utils/vision/data_transformer
utils/vision/blob_fetcher
========================================= =====================================================================
List Brief
========================================= =====================================================================
`dragon.utils.vision.im2db`_ Make the sequential database for images.
`dragon.utils.vision.data_batch`_ Efficient Batch data provider based on `LMDB`_.
`dragon.utils.vision.data_reader`_ Queue encoded string from `LMDB`_.
`dragon.utils.vision.data_transformer`_ Queue transformed images from `DataReader`_.
`dragon.utils.vision.blob_fetcher`_ Queue blobs from `DataTransformer`_.
========================================= =====================================================================
.. _LMDB: http://lmdb.readthedocs.io/en/release
.. _dragon.utils.vision.im2db: utils/vision/database.html
.. _DataReader: utils/vision/data_reader.html#dragon.utils.vision.data_reader
.. _DataTransformer: utils/vision/data_transformer.html#dragon.utils.vision.data_transformer
.. _dragon.utils.vision.data_batch: utils/vision/data_batch.html
.. _dragon.utils.vision.data_reader: utils/vision/data_reader.html
.. _dragon.utils.vision.data_transformer: utils/vision/data_transformer.html
.. _dragon.utils.vision.blob_fetcher: utils/vision/blob_fetcher.html
\ No newline at end of file
==================
:mod:`BlobFetcher`
==================
.. toctree::
:hidden:
.. currentmodule:: dragon.utils.vision.blob_fetcher
.. autoclass:: BlobFetcher
:members:
.. automethod:: __init__
.. _DataTransformer: data_transformer.html#dragon.utils.vision.data_transformer
\ No newline at end of file
================
:mod:`DataBatch`
================
.. toctree::
:hidden:
.. currentmodule:: dragon.utils.vision.data_batch
.. autoclass:: DataBatch
:members:
.. automethod:: __init__
\ No newline at end of file
=================
:mod:`DataReader`
=================
.. toctree::
:hidden:
.. currentmodule:: dragon.utils.vision.data_reader
.. autoclass:: DataReader
:members:
.. automethod:: __init__
.. _LMDB: http://lmdb.readthedocs.io/en/release
\ No newline at end of file
======================
:mod:`DataTransformer`
======================
.. toctree::
:hidden:
.. currentmodule:: dragon.utils.vision.data_transformer
.. autoclass:: DataTransformer
:members:
.. automethod:: __init__
.. _DataReader: data_reader.html#dragon.io.data_reader
\ No newline at end of file
===============
:mod:`Database`
===============
.. toctree::
:hidden:
Quick Reference
---------------
==================== =============================================================================
List Brief
==================== =============================================================================
`resize_image`_ Resize the image by the shortest edge.
`make_db`_ Make the image database.
==================== =============================================================================
API Reference
-------------
.. automodule:: dragon.utils.vision.im2db
:members:
.. _resize_image: #dragon.utils.vision.im2db.resize_image
.. _make_db: #dragon.utils.vision.im2db.make_db
\ No newline at end of file
================
:mod:`dragon.vm`
================
Overview
--------
|para| Although the proposed `TinyDragon`_ can contribute a framework, we still desire it to be humanized.
An interesting idea is that: basic primitives of `Theano`_ can be used for building `Caffe`_ or `TensorFlow`_,
thus, these modern frameworks can share a common backend if providing enough operator kernels.
|para| In this section, we demonstrate a cross-frameworks frontend is feasible, and further more, will get
benefit from all participating crucial interfaces especially when one is not reasonable.
VirtualBox
----------
.. toctree::
:hidden:
vm/caffe
vm/theano
vm/torch
==================== ====================================================================================
List Brief
==================== ====================================================================================
`Theano`_ **Theano** is an inception of the modern deep learning frameworks.
`Caffe`_ **Caffe** is one of the most famous deep learning framework for Computer Vision.
`PyTorch`_ **PyTorch** provides straight-forward operations on research prototyping.
==================== ====================================================================================
.. |para| raw:: html
<p style="text-indent:1.5em; font-size: 18px; max-width: 830px;">
.. _TinyDragon: ../index.html#tinydragon
.. _Theano: vm/theano.html
.. _Caffe: vm/caffe.html
.. _PyTorch: vm/torch.html
.. _TensorFlow: ../index.html#tensorflow
============
:mod:`Caffe`
============
Abstraction
-----------
|para| `Caffe`_ is one of the most famous deep learning framework for **Computer Vision**.
|para| However, it seems to be stuck due to the the poor memory optimization against very deep neural nets.
Besides, lacking of flexible automatic differentiation, it is awful to model multi-nets algorithms,
such as `GAN`_ and `Deterministic PolicyGradient`_.
|para| We implement it based on the backend of Dragon thorough native Python language.
Our work is very different from the official Python wrappers, a.k.a, the **PyCaffe**, which comes from
the exports of `BoostPython`_ based on C++ language.
|para| We demonstrate that even completely drop the **Net** topology proposed by `Jia et al. (2014)`_,
any **Graph** based deep learning frameworks(*Dragon*, *Theano*, *MXNet*, or *TensorFlow*)
can inherit almost specifics from `Caffe`_ also.
Related Work
------------
|paratitle| **Fast RCNN**
|para| Inspired by the `SolverWrapper`_, which disabled and reimplemented the
optimization process for object detection system, we tried to implement `Solver`_ completely in Python environment.
Benefited from the flexible **Updater** designed in the backend, we accomplished it with several python codes,
specializing in **Dynamic Learning Rate**, **Custom Training Loops**, and **Cross Validation**.
|paratitle| **Theano**
|para| The **Net** used in `Caffe`_ is redundant, thus,
we propagate the data flows in the **Graph** equivalently.
Specifically, we use `theano.function(inputs, outputs)`_ to collect the inputs and outputs of `Net`_,
then, generate the **Computation Graph** descriptions for the backend to optimize.
Note that all DL frameworks in **VirtualBox** share the same descriptions,
leading the results to be deterministic and reproduceable.
|paratitle| **Keras**
|para| Referring to **Keras**, whose API is designed to wrap existing backends,
we **IMPLEMENT** most `Layers`_ of `Caffe`_ without any efforts.
Our backend has provided both the latest and optimized deep learning operators,
that outperforms the original `Caffe`_ or other forked ones.
Architectures
-------------
.. toctree::
:hidden:
caffe/layer
caffe/net
caffe/solver
caffe/misc
|paratitle| **Layer**
|para| **Layer** is the basic structure for parsing text format definition.
By taking the advantages of python based `protobuf`_,
we can parse and document parameters of various layers.
Following the `Caffe`_ that before dismantling headers(such as `62ed0d2`_),
we categorize these layers into six sections:
|sectitle| □ |nbsp| `Data`_ - How to prefetch data before feeding to the Net.
|sectitle| □ |nbsp| `Vision`_ - Vision relevant layers, such as Convolution and Pooling.
|sectitle| □ |nbsp| `Neuron`_ - Neuron relevant layers, most of those are activations.
|sectitle| □ |nbsp| `Common`_ - Layers using BLAS or applying on NDArray.
|sectitle| □ |nbsp| `Loss`_ - Several frequently used loss functions.
|sectitle| □ |nbsp| `MPI`_ - MPI relevant layers, for model parallelism.
|context| For detailed Documentation, see: `Layer`_.
|paratitle| **Net**
|para| **Net** supports the most exporting interfaces used in **PyCaffe**.
We implement it completely in the python environment, which provides much conveniences,
especially when extending the modern architectures of **Convolutional Neural Networks**.
|context| For detailed Documentation, see: `Net`_.
|paratitle| **Solver**
|para| **Solver** merges updates to optimize the `Net`_.
We simplified it from the original C++ implementation, that brings more unconstrained tricks
for tuning hyper parameters, e.g., the learning rate.
|context| For detailed Documentation, see: `Solver`_.
|paratitle| **Misc**
|para| The internal settings(e.g. GPU, Random Seed) can be configured everywhere by singleton,
we contribute this to the designing of `Global Context`_, which was also taken by `Girshick (2015)`_.
In order to implement it, we bind these settings to the `dragon.config`_.
|context| For detailed Documentation, see: `Misc`_.
.. _Caffe: http://caffe.berkeleyvision.org
.. _62ed0d2: https://github.com/BVLC/caffe/tree/62ed0d2bd41a730397e718bae4354c9a5a722624
.. _BoostPython: http://www.boost.org/
.. _Jia et al. (2014): https://arxiv.org/abs/1408.5093
.. _Girshick (2015): https://github.com/rbgirshick/fast-rcnn/blob/master/lib/fast_rcnn/config.py
.. _GAN: https://arxiv.org/abs/1406.2661
.. _Deterministic PolicyGradient: http://proceedings.mlr.press/v32/silver14.html
.. _SolverWrapper: https://github.com/rbgirshick/fast-rcnn/blob/e68366925d18fde83e865b894022d1d278f3f758/lib/fast_rcnn/train.py#L20
.. _Global Context: https://github.com/BVLC/caffe/blob/ef2eb4b9369e4c0db5cfc92cc9c8e4d4497d421e/include/caffe/common.hpp#L102
.. _protobuf: https://github.com/google/protobuf
.. _dragon.config: ../config.html
.. _theano.function(inputs, outputs): theano/compile.html#dragon.vm.theano.compile.function.function
.. _Solver: caffe/solver.html
.. _Net: caffe/net.html
.. _Misc: caffe/misc.html
.. _Layers: caffe/layer.html
.. _Layer: caffe/layer.html
.. _Data: caffe/layer.html#data
.. _Vision: caffe/layer.html#vision
.. _Neuron: caffe/layer.html#neuron
.. _Common: caffe/layer.html#common
.. _Loss: caffe/layer.html#loss
.. _MPI: caffe/layer.html#mpi
.. |nbsp| raw:: html
&nbsp
.. |br| raw:: html
<br />
.. |paratitle| raw:: html
<p style="font-size: 20px">
.. |sectitle| raw:: html
<p style="text-indent:1em; font-size: 18px">
.. |para| raw:: html
<p style="text-indent:1.5em; font-size: 18px; max-width: 830px;">
.. |context| raw:: html
<p style="font-size: 18px; max-width: 830px;">
===========
:mod:`Misc`
===========
.. toctree::
:hidden:
Quick Reference
---------------
========================= ============================================================================
List Brief
========================= ============================================================================
`caffe.set_mode_cpu`_ Set to the CPU mode.
`caffe.set_mode_gpu`_ Set to the GPU mode.
`caffe.set_device`_ Set the active device.
`caffe.set_random_seed`_ Set the global random seed.
`caffe.root_solver`_ Whether this node is root.
`caffe.set_root_solver`_ Set this node to the root.
========================= ============================================================================
API Reference
-------------
.. automodule:: dragon.vm.caffe.misc
:members:
.. _caffe.set_mode_cpu: #dragon.vm.caffe.misc.set_mode_cpu
.. _caffe.set_mode_gpu: #dragon.vm.caffe.misc.set_mode_gpu
.. _caffe.set_device: #dragon.vm.caffe.misc.set_device
.. _caffe.set_random_seed: #dragon.vm.caffe.misc.set_random_seed
.. _caffe.root_solver: #dragon.vm.caffe.misc.root_solver
.. _caffe.set_root_solver: #dragon.vm.caffe.misc.set_root_solver
.. _set_mode_cpu(_caffe.cpp, L51): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/_caffe.cpp#L51
.. _set_mode_gpu(_caffe.cpp, L52): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/_caffe.cpp#L52
.. _SetDevice(common.cpp, L65): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/common.cpp#L65
.. _set_random_seed(_caffe.cpp, L71): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/_caffe.cpp#L71
.. _root_solver(common.hpp, L164): https://github.com/BVLC/caffe/blob/b9ea0267851ccc7f782327408fe7953ba0f13c53/include/caffe/common.hpp#L164
.. _set_root_solver(common.hpp, L165): https://github.com/BVLC/caffe/blob/b9ea0267851ccc7f782327408fe7953ba0f13c53/include/caffe/common.hpp#L165
==========
:mod:`Net`
==========
.. toctree::
:hidden:
Quick Reference
---------------
========================= =============================================================================
List Brief
========================= =============================================================================
`Net.copy_from`_ Copy the parameters from the binary proto file.
`Net.forward`_ Forward Pass.
`Net.backward`_ Backward Pass.
`Net.function`_ Forward + Backward Pass.
`Net.save`_ Save the parameters into a binary file.
`Net.blobs`_ Return the blobs.
`Net.params`_ Return the parameters.
`Net.trainable_params`_ Return the trainable parameters.
`Net.inputs`_ Return the inputs of net.
`Net.outputs`_ Return the outputs of net.
========================= =============================================================================
API Reference
-------------
.. currentmodule:: dragon.vm.caffe.net
.. autoclass:: Net
:members:
.. automethod:: __init__
.. autoclass:: PartialNet
:members:
.. _Net.copy_from: #dragon.vm.caffe.net.Net.copy_from
.. _Net.forward: #dragon.vm.caffe.net.Net.forward
.. _Net.backward: #dragon.vm.caffe.net.Net.backward
.. _Net.save: #dragon.vm.caffe.net.Net.save
.. _Net.blobs: #dragon.vm.caffe.net.Net.blobs
.. _Net.params: #dragon.vm.caffe.net.Net.params
.. _Net.trainable_params: #dragon.vm.caffe.net.Net.trainable_params
.. _Net.inputs: #dragon.vm.caffe.net.Net.inputs
.. _Net.outputs: #dragon.vm.caffe.net.Net.outputs
.. _Net.function: #dragon.vm.caffe.net.Net.function
.. _NetInit(proto_txt, phase): #dragon.vm.caffe.net.Net.NetInit
.. _NetInitLoad(proto_txt, model, phase): #dragon.vm.caffe.net.Net.NetInitLoad
.. _workspace.Snapshot(*args, **kwargs): ../../core/workspace.html#dragon.core.workspace.Snapshot
.. _workspace.Restore(*args, **kwargs): ../../core/workspace.html#dragon.core.workspace.Restore
.. _Net_Init(_caffe.cpp, L109): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/_caffe.cpp#L109
.. _Net_Init_Load(_caffe.cpp, L137): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/_caffe.cpp#L137
.. _FilterNet(net.cpp, L259): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/net.cpp#L259
.. _Init(net.cpp, L44): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/net.cpp#L44
.. _ForwardBackward(net.cpp, L85): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/include/caffe/net.hpp#L85
.. _CopyTrainedLayersFromBinaryProto(net.cpp, L780): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/net.cpp#L780
.. _Net_forward(pycaffe.py, L88): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/pycaffe.py#L88
.. _Net_backward(pycaffe.py, L137): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/pycaffe.py#L137
.. _Net_Save(_caffe.cpp, L153): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/_caffe.cpp#L153
.. _Net_blobs(pycaffe.py, L25): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/pycaffe.py#L25
.. _Net_params(pycaffe.py, L58): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/pycaffe.py#L58
.. _Net_inputs(pycaffe.py, L73): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/pycaffe.py#L73
.. _Net_outputs(pycaffe.py, L81): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/python/caffe/pycaffe.py#L81
.. _theano.function(*args, **kwargs): ../theano/compile.html#dragon.vm.theano.compile.function.function
\ No newline at end of file
=============
:mod:`Solver`
=============
.. toctree::
:hidden:
Quick Reference
---------------
==================== =============================================================================
List Brief
==================== =============================================================================
`Solver.step`_ Step the train net.
`Solver.snapshot`_ Snapshot the parameters of train net.
`Solver.net`_ Return the train net.
`Solver.test_nets`_ Return the test nets.
`Solver.iter`_ Return or Set the current iteration.
`Solver.lr`_ Return or Set the current learning rate.
==================== =============================================================================
API Reference
-------------
.. currentmodule:: dragon.vm.caffe.solver
.. autoclass:: Solver
:members:
.. automethod:: __init__
.. _Net.function(*args, **kwargs): net.html#dragon.vm.caffe.net.Net.function
.. _workspace.Snapshot(*args, **kwargs): ../../core/workspace.html#dragon.core.workspace.Snapshot
.. _Solver.step: #dragon.vm.caffe.solver.Solver.step
.. _Solver.snapshot: #dragon.vm.caffe.solver.Solver.snapshot
.. _Solver.net: #dragon.vm.caffe.solver.Solver.net
.. _Solver.test_nets: #dragon.vm.caffe.solver.Solver.test_nets
.. _Solver.iter: #dragon.vm.caffe.solver.Solver.iter
.. _Solver.lr: #dragon.vm.caffe.solver.Solver.lr
.. _[LeCun et.al, 1998]: http://yann.lecun.com/exdb/publis/#lecun-98b
.. _[Sutskever et.al, 2012]: http://www.cs.utoronto.ca/~bonner/courses/2016s/csc321/lectures/lec6.pdf
.. _[Hinton et.al, 2013]: http://www.cs.utoronto.ca/~bonner/courses/2016s/csc321/lectures/lec6.pdf
.. _[Kingma & Ba, 2014]: https://arxiv.org/abs/1412.6980
.. _SolverWrapper: https://github.com/rbgirshick/py-faster-rcnn/blob/4e199d792f625cf712ca9b9a16278bafe0806201/lib/fast_rcnn/train.py#L20``
.. _InitTrainNet(solver.cpp, L63): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/solver.cpp#L63
.. _InitTestNets(solver.cpp, L104): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/solver.cpp#L104
.. _GetLearningRate(solver.cpp, L27): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/solvers/sgd_solver.cpp#L27
.. _Step(solver.cpp, L180): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/solver.cpp#L180
.. _Test(solver.cpp, L328): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/solver.cpp#L328
.. _Snapshot(solver.cpp, L403): https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/solver.cpp#L403
.. _SolverParameter.base_lr: https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/proto/caffe.proto#L146
.. _SolverParameter.momentum: https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/proto/caffe.proto#L174
.. _SolverParameter.momentum2: https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/proto/caffe.proto#L217
.. _SolverParameter.rms_decay: https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/proto/caffe.proto#L221
.. _SolverParameter.delta: https://github.com/BVLC/caffe/blob/effcdb0b62410b2a6a54f18f23cf90733a115673/src/caffe/proto/caffe.proto#L215
.. autoclass:: SGDSolver
:members:
.. autoclass:: NesterovSolver
:members:
.. autoclass:: RMSPropSolver
:members:
.. autoclass:: AdamSolver
:members:
\ No newline at end of file
=============
:mod:`Theano`
=============
Abstraction
-----------
|para| `Theano`_ is an inception of the modern deep learning frameworks.
|para| We find that the fundamentals of `compile`_ are quite useful to wrap the primitives of computation graph,
thus, instead of defining any primitives that are hard to remember, we still prefer the `Theano`_.
|para| We implement it based on the backend of Dragon thorough native Python language.
All operators are compiled offline, which is more similar to `TensorFlow`_ but not the original `Theano`_.
|para| Our implemented **Theano** is also easy to debug or extend, it could be a substitution for supporting
the early codes of Deep Learning.
Related Work
------------
|paratitle| **Caffe**
|para| `Caffe`_ takes the fine-grained layers to form the most operations of Deep Learning.
|para| Comparing with the real-time compiling, **Factory Pattern** provides a faster method
to create the computation graph based on the uncertain topology
while lacks optimizations both on the time and space. We proposed several simple algorithms
to optimize the raw graph by taking the text format topology of `protobuf`_,
which contributes an efficient `compile`_ module for **Theano**.
|paratitle| **Keras**
|para| `Keras`_ is smart enough to invent new fine-grained API to unify various backends.
|para| We DO NOT follow it because the computations performed by different backends are confused.
Besides, the efforts to learn `Keras`_ are also expensive.
|para| Our implemented **Theano** completely takes the advantages of `VirtualTensor`_, while
still could be as light as `Keras`_.(*LESS THAN 2000 LINES!*)
Architectures
-------------
.. toctree::
:hidden:
theano/compile
theano/tensor
|paratitle| **Compile**
|para| This module consists several crucial primitives to drive the backend of Dragon.
We find these primitives useful through injecting the intentions of programming
(such as **Feed/Fetch**, **Net Topology**, and **Control Flow**)
into the virtual machine, instead of explicitly declaring and creating.
|sectitle| □ |nbsp| `Function`_
|para| Unlike `Caffe2`_, we prefer this primitive to declaring a graph and stuffing operators,
as a graph can be confirmed and further optimized if only the inputs and outputs are deterministic.
|para| We also remove the naive arithmetic update operations, use the fine-grained `Updater`_ instead.
Our implemented `Updater`_ provides the speedup for large-scale distributed training,
which will enhance all frameworks in the VirtualBox.
|sectitle| □ |nbsp| `Shared`_
|para| This primitive is a simple wrapper of `FeedTensor`_.
|para| We remove the mechanism of `SharedVaraible`_ due to the **memory-storage** is taken by the backend.
Following the `Caffe2`_ and `TensorFlow`_, we attribute it to the **Feed** of data streams.
|context| For detailed Documentation, see: `Compile`_.
|paratitle| **Tensor**
|para| This module provides massive methods based on **Tensor**.
|para| The structure itself is obscure in `Theano`_, while **Symbolic Variable** is more frequently represented.
We simplify the messy representations by the unified `VirtualTensor`_ structure,
that **Tensor** is generally represented any n-dimensions arrays.
|para| All methods in this module will share the `Ops`_ library of Dragon.
We are sorry for removing some odd implementations supported by the original `Theano`_.
|para| Inheriting from the hierarchy of `Theano`_, we categorize these methods as follows:
|sectitle| □ |nbsp| `Basic`_
|sectitle| □ |nbsp| `Variable`_
|sectitle| □ |nbsp| `Initializer`_
|sectitle| □ |nbsp| `Operator`_
|sectitle| □ |nbsp| `NNet`_
|context| For detailed Documentation, see: `Tensor`_.
.. |nbsp| raw:: html
&nbsp
.. |br| raw:: html
<br />
.. |paratitle| raw:: html
<p style="font-size: 20px">
.. |sectitle| raw:: html
<p style="text-indent:1em; font-size: 18px">
.. |para| raw:: html
<p style="text-indent:1.5em; font-size: 18px; max-width: 830px;">
.. |context| raw:: html
<p style="font-size: 18px; max-width: 830px;">
.. _Theano: http://deeplearning.net/software/theano
.. _TensorFlow: http://www.tensorflow.org
.. _compile: theano/compile.html
.. _Tensor: theano/tensor.html
.. _VirtualTensor: ../core/tensor.html
.. _protobuf: https://github.com/google/protobuf
.. _Caffe: caffe.html
.. _Caffe2: https://caffe2.ai
.. _Keras: https://keras.io
.. _Updater: ../updaters.html
.. _Ops: ../ops.html
.. _Function: theano/compile.html#dragon.vm.theano.compile.function.function
.. _Shared: theano/compile.html#dragon.vm.theano.compile.sharedvalue.shared
.. _FeedTensor: ../core/workspace.html#dragon.core.workspace.FeedTensor
.. _SharedVaraible: http://deeplearning.net/software/theano/library/compile/shared.html
.. _Basic: theano/tensor.html#basic
.. _Variable: theano/tensor.html#variable
.. _Initializer: theano/tensor.html#initializer
.. _Operator: theano/tensor.html#operator
.. _NNet: theano/tensor.html#nnet
==============
:mod:`Compile`
==============
.. toctree::
:hidden:
Quick Reference
---------------
============================== =======================================================================
List Brief
============================== =======================================================================
`function`_ Return a callable function that will compute outputs.
`shared`_ Construct a Tensor initialized with numerical values.
============================== =======================================================================
API Reference
-------------
.. automodule:: dragon.vm.theano.compile.function
:members:
.. automodule:: dragon.vm.theano.compile.sharedvalue
:members:
.. _config.SetDebugMode(*args, **kwargs): ../../config.html#dragon.config.SetDebugMode
.. _memonger.share_grads(*args, **kwargs): ../../memonger.html#dragon.memonger.share_grads
.. _config.EnableCPU(): ../../config.html#dragon.config.EnableCPU
.. _config.EnableCUDA(*args, **kwargs): ../../config.html#dragon.config.EnableCUDA
.. _config.SetRandomSeed(*args, **kwargs): ../../config.html#dragon.config.SetRandomSeed
.. _T.grad(*args, **kwargs): tensor.html#dragon.vm.theano.gradient.grad
.. _function: #dragon.vm.theano.compile.function.function
.. _shared: #dragon.vm.theano.compile.sharedvalue.shared
\ No newline at end of file
=============
:mod:`Tensor`
=============
.. toctree::
:hidden:
Basic
-----
============================== =======================================================================
List Brief
============================== =======================================================================
`grad`_ Compute the gradients for variables with respect to the cost.
`disconnected_grad`_ Return the input with truncated gradient flow.
============================== =======================================================================
Variable
--------
============================== =======================================================================
List Brief
============================== =======================================================================
`scalar`_ Return a scalar variable.
`iscalar`_ Return a int32 scalar variable.
============================== =======================================================================
Initializer
-----------
============================== =======================================================================
List Brief
============================== =======================================================================
`constant`_ Initialize a tensor with constant value.
`zeros`_ Initialize a tensor with zeros.
`zeros_like`_ Initialize a tensor with zeros, refer the shape of another tensor.
`ones`_ Initialize a tensor with ones.
`ones_like`_ Initialize a tensor with ones, refer the shape of another tensor.
============================== =======================================================================
Operator
--------
============================== =======================================================================
List Brief
============================== =======================================================================
`cast`_ Cast input to the tensor of specific data type.
`dot`_ Calculate A dot B.
`transpose`_ Transpose the input according to the given permutations.
`sum`_ Compute the sum along the given axis.
`mean`_ Compute the mean along the given axis.
`prod`_ Compute the product along the given axis.
`argmax`_ Compute the indices of maximum elements along the given axis.
`argmin`_ Compute the indices of minimum elements along the given axis.
`square`_ Calculate the square of input.
`sqrt`_ Calculate the sqrt of input.
`pow`_ Calculate the power of input.
`exp`_ Calculate the exponential of input.
`log`_ Calculate the logarithm of input.
`clip`_ Clip the input to be between min and max.
`join`_ Convenience function to concatenate along the given axis.
`stack`_ Stack the inputs along the given axis.
`concatenate`_ Concatenate the inputs along the given axis.
`reshape`_ Reshape the dimensions of input.
`flatten`_ Flatten the input by keeping the specific dimensions.
`repeat`_ Repeat the input along the given axis.
`tile`_ Tile the input according to the given multiples.
`arange`_ Return a vector of elements by arange.
`cumsum`_ Compute the cumulative sum along the given axis.
`cumprod`_ Compute the cumulative product along the given axis.
`to_one_hot`_ Generate a matrix where each row corresponds to the one hot encoding.
============================== =======================================================================
NNet
----
============================== ===============================================================================
List Brief
============================== ===============================================================================
`batch_normalization`_ Batch Normalization, introduced by `[Ioffe & Szegedy, 2015]`_
`relu`_ Rectified Linear Unit function, introduces by `[Nair & Hinton, 2010]`_.
`softmax`_ Softmax function.
`categorical_crossentropy`_ Compute the categorical cross-entropy between input and target distribution.
`sigmoid`_ Sigmoid function.
`tanh`_ TanH function.
`binary_crossentropy`_ Compute the binary cross-entropy between input and target distribution.
============================== ===============================================================================
API Reference
-------------
.. automodule:: dragon.vm.theano.gradient
:members:
.. automodule:: dragon.vm.theano.tensor.basic
:members:
.. automodule:: dragon.vm.theano.tensor.extra_ops
:members:
.. automodule:: dragon.vm.theano.tensor.nnet
:members:
.. _grad: #dragon.vm.theano.gradient.grad
.. _disconnected_grad: #dragon.vm.theano.gradient.disconnected_grad
.. _scalar: #dragon.vm.theano.tensor.basic.scalar
.. _iscalar: #dragon.vm.theano.tensor.basic.iscalar
.. _constant: #dragon.vm.theano.tensor.basic.constant
.. _zeros: #dragon.vm.theano.tensor.basic.zeros
.. _zeros_like: #dragon.vm.theano.tensor.basic.zeros_like
.. _ones: #dragon.vm.theano.tensor.basic.ones
.. _ones_like: #dragon.vm.theano.tensor.basic.ones_like
.. _cast: #dragon.vm.theano.tensor.basic.cast
.. _dot: #dragon.vm.theano.tensor.basic.dot
.. _transpose: #dragon.vm.theano.tensor.basic.transpose
.. _sum: #dragon.vm.theano.tensor.basic.sum
.. _mean: #dragon.vm.theano.tensor.basic.mean
.. _prod: #dragon.vm.theano.tensor.basic.prod
.. _argmax: #dragon.vm.theano.tensor.basic.argmax
.. _argmin: #dragon.vm.theano.tensor.basic.argmin
.. _square: #dragon.vm.theano.tensor.basic.square
.. _sqrt: #dragon.vm.theano.tensor.basic.sqrt
.. _pow: #dragon.vm.theano.tensor.basic.pow
.. _exp: #dragon.vm.theano.tensor.basic.exp
.. _log: #dragon.vm.theano.tensor.basic.log
.. _clip: #dragon.vm.theano.tensor.basic.clip
.. _join: #dragon.vm.theano.tensor.basic.join
.. _stack: #dragon.vm.theano.tensor.basic.stack
.. _concatenate: #dragon.vm.theano.tensor.basic.concatenate
.. _reshape: #dragon.vm.theano.tensor.basic.reshape
.. _flatten: #dragon.vm.theano.tensor.basic.flatten
.. _repeat: #dragon.vm.theano.tensor.basic.repeat
.. _tile: #dragon.vm.theano.tensor.basic.tile
.. _arange: #dragon.vm.theano.tensor.basic.arange
.. _cumsum: #dragon.vm.theano.tensor.extra_ops.cumsum
.. _cumprod: #dragon.vm.theano.tensor.extra_ops.cumprod
.. _to_one_hot: #dragon.vm.theano.tensor.extra_ops.to_one_hot
.. _batch_normalization: #dragon.vm.theano.tensor.nnet.batch_normalization
.. _relu: #dragon.vm.theano.tensor.nnet.relu
.. _softmax: #dragon.vm.theano.tensor.nnet.softmax
.. _categorical_crossentropy: #dragon.vm.theano.tensor.nnet.categorical_crossentropy
.. _sigmoid: #dragon.vm.theano.tensor.nnet.sigmoid
.. _tanh: #dragon.vm.theano.tensor.nnet.tanh
.. _binary_crossentropy: #dragon.vm.theano.tensor.nnet.binary_crossentropy
.. _[Ioffe & Szegedy, 2015]: https://arxiv.org/abs/1502.03167
.. _[Nair & Hinton, 2010]: http://www.csri.utoronto.ca/~hinton/absps/reluICML.pdf
============
:mod:`Torch`
============
Abstraction
-----------
|para| `PyTorch`_ provides straight-forward operations on research prototyping.
|para| We are aware that **Dragon** is a graph-based framework with strictly naming
for tensors, operators, and workspaces, while `Torch`_ is not.
A simple way to bridge their differences is **JIT**, which traces the anonymous expressions,
indicates a series of executions to the backend. If so, **AutoGrad** will just be a trick(Remember the *Chain Rule*).
|para| Rewriting the GC(*Garbage Collection*) is crucial in this role,
as the costly deconstruction on memories and operators must be avoided.
We could either persist a Operator(i.e. **Module**),
or reuse the several memories by turns(i.e. **MemoryPool**), if naming them formally.
|para| We are still working hard to cover the original PyTorch operators,
however, a bunch of extended operators in many other frameworks can be used.
Our **PyTorch** will be unique and more powerful than the official one.
Related Work
------------
|paratitle| **Proto-based Intermediate Representation**
|para| Recent years, several powerful frameworks choose the ProtocolBuffer to
describe the operators with various arguments, including `Caffe`_, `Caffe2`_, `TensorFlow`_, and `ONNX`_.
The most important reason is that, these descriptors can be easily serialized and sent to the backend.
With the help of **Factory Pattern**, we have had an elegant way to dispatch the executions, while not
call them imperatively. This way is also known as the **Declarative Programming**.
|para| Attaching the IR(Intermediate Representation) takes the following advantages:
* Traceable pipelines, much helpful for visualizing and debugging.
* Deterministic executions, detailed optimization can be applied.
* Efficient deployments, data-flows has been well organized.
|para| A good news is that, we can reduce the overhead of IR below 5% of computation time,
which means the dynamic graph could work as fast as the static graph while retain the flexibility.
|paratitle| **Caffe2**
|para| We have noticed that some developers discouraged the **Declarative Programming** in 2017 and early 2018,
due to the counter-intuitive building of computation graph. Actually, `Caffe2`_ had published Operator-Wise execution
(a.k.a, *workspace.RunOperator()*) since 2016. In other words, **Imperative Programming** is the subset of **Declarative Programming**,
if we process the declaration implicitly. This mechanism is sometimes called **JIT** by someone.
Architectures
-------------
.. toctree::
:hidden:
.. _Torch: http://torch.ch
.. _PyTorch: https://pytorch.org
.. _Caffe: http://caffe.berkeleyvision.org
.. _Caffe2: http://caffe2.ai
.. _TensorFlow: https://www.tensorflow.org
.. _ONNX: https://onnx.ai
.. |nbsp| raw:: html
&nbsp
.. |br| raw:: html
<br />
.. |paratitle| raw:: html
<p style="font-size: 20px">
.. |sectitle| raw:: html
<p style="text-indent:1em; font-size: 18px">
.. |para| raw:: html
<p style="text-indent:1.5em; font-size: 18px; max-width: 830px;">
.. |context| raw:: html
<p style="font-size: 18px; max-width: 830px;">
Dragon - Python API
===================
Dragon is a computation graph based distributed deep learning framework.
For using it, import as follows:
.. code-block:: python
import dragon
Style Orientation
-----------------
However, it will not help you much because Dragon is designed without systemic API.
We have extended it with **FOUR** Programming Styles:
TinyDragon
##########
*TinyDragon* takes a very light weight programming style.
Our goal is to reduce extra unnecessary structures or interfaces. Therefore,
in addition to feed or fetch, the last thing is designing a objective function through available operators.
It mainly uses the following components:
* `Tensor`_
* `Operators`_
* `Updaters`_
* `Workspace`_
* `Function`_
* `Grad`_
Caffe
#####
*Caffe* is implemented basing on the backend of Dragon thorough native Python language.
Our work is very different from the official Python wrappers, a.k.a, the **PyCaffe**, which comes from
the exports of **BoostPython** based on C++ language.
It mainly uses the following components:
* `Tensor`_
* `Layer`_
* `Net`_
* `Solver`_
* `Misc`_
Theano
######
*Theano* is an inception of the modern deep learning frameworks.
We implement it based on the backend of Dragon thorough native Python language.
All operators are compiled offline, which is more similar to *TensorFlow* but not the original *Theano*.
It mainly uses the following components:
* `Tensor`_
* `T`_
* `Updaters`_
* `Function`_
* `Grad`_
TensorFlow
##########
COMING SOON......
Table of Contents
-----------------
.. toctree::
:hidden:
contents/config
contents/ops
contents/updaters
contents/memonger
contents/core
contents/utils
contents/operators
contents/vm
contents/tools
Quick Shortcut
##############
===================== ======================================================================
`dragon.config`_ The global configures.
`dragon.ops`_ The exhibition of available operators.
`dragon.updaters`_ The exhibition of available updaters.
`dragon.memonger`_ The extreme memory optimizer.
===================== ======================================================================
Packages
########
===================== =====================================================================
`dragon.core`_ The core package.
`dragon.utils`_ The utils package.
`dragon.operators`_ The operators package.
`dragon.tools`_ The tools package.
`dragon.vm`_ The vm package.
===================== =====================================================================
.. _dragon.config: contents/config.html
.. _dragon.ops: contents/ops.html
.. _dragon.core: contents/core.html
.. _dragon.core.tensor.Tensor: contents/core/tensor.html
.. _dragon.core.workspace: contents/core/workspace.html
.. _dragon.utils: contents/utils.html
.. _dragon.operators: contents/operators.html
.. _dragon.updaters: contents/updaters.html
.. _dragon.memonger: contents/memonger.html
.. _dragon.tools: contents/tools.html
.. _dragon.vm: contents/vm.html
.. _Tensor: contents/core/tensor.html
.. _Workspace: contents/core/workspace.html
.. _Operators: contents/ops.html
.. _Updaters: contents/updaters.html
.. _Layer: contents/vm/caffe/layer.html
.. _Net: contents/vm/caffe/net.html
.. _Solver: contents/vm/caffe/solver.html
.. _Misc: contents/vm/caffe/misc.html
.. _Function: contents/vm/theano/compile.html#dragon.vm.theano.compile.function.function
.. _Grad: contents/vm/theano/tensor.html#dragon.vm.theano.gradient.grad
.. _T: contents/vm/theano/tensor.html
.. _Caffe: contents/vm/caffe.html
.. |br| raw:: html
<br />
\ No newline at end of file
# ---------------- Welcom To Use Dragon ----------------
project(dragon)
cmake_minimum_required(VERSION 3.0.2)
# ---------------- Welcom To Use Dragon ----------------
# ---------------- User Config ----------------
# Set optional buildings
option(BUILD_PYTHON_API "Set ON to build PYTHON API" ON)
option(BUILD_CXX_API "Set ON to build CXX API" OFF)
# Set optional libraries
option(WITH_CUDA "Set ON to use CUDA" ON)
option(WITH_CUDNN "Set ON to use CUDNN" ON)
option(WITH_OMP "Set ON to use OpenMP" ON)
option(WITH_MPI "Set ON to use MPI" OFF)
option(WITH_NCCL "Set ON to use NCCL" OFF)
# Set your 3rdparty
if (NOT THIRD_PARTY_DIR)
set(THIRD_PARTY_DIR ${PROJECT_SOURCE_DIR}/../ThirdParty)
endif()
# Set your protobuf compiler(protoc) if necessary
# if not, a default "protoc" in the environment path will be used
if (NOT PROTOC_EXECUTABLE)
set(PROTOC_EXECUTABLE protoc)
endif()
# Set your python "interpreter" if necessary
# if not, a default interpreter will be used
# here, provide several examples:
if (NOT PYTHON_EXECUTABLE)
# set(PYTHON_EXECUTABLE /usr/bin/python) # Linux && OSX, Builtin Python
# set(PYTHON_EXECUTABLE /X/anaconda/bin/python) # Linux && OSX, Anaconda
# set(PYTHON_EXECUTABLE X:/Anaconda/python) # Win, Anaconda
endif()
# Set CUDA compiling architecture
# Remove "compute_70/sm_70" if using CUDA 8.0
set(CUDA_ARCH -gencode arch=compute_30,code=sm_30
-gencode arch=compute_35,code=sm_35
-gencode arch=compute_50,code=sm_50
-gencode arch=compute_60,code=sm_60
-gencode arch=compute_70,code=sm_70)
# ---------------- User Config ----------------
# ---------------- Do Not Edit Following Items ----------------
# __----~~~~~~~~~~~------___
# . . ~~//====...... __--~ ~~
# -. \_|// |||\\ ~~~~~~::::... /~
# ___-==_ _-~o~ \/ ||| \\ _/~~-
# __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~
# _-~~ .=~ | \\-_ '-~7 /- / || \ /
# .~ .~ | \\ -_ / /- / || \ /
# / ____ / | \\ ~-_/ /|- _/ .|| \ /
# |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\
# ' ~-| /| |-~\~~ __--~~
# |-~~-_/ | | ~\_ _-~ /\
# / \ \__ \/~ \__
# _--~ _/ | .-~~____--~-/ ~~==.
# ((->/~ '.|||' -_| ~~-/ , . _||
# -_ ~\ ~~---l__i__i__i--~~_/
# _-~-__ ~) \--______________--~~
# //.-~~~-~_--~- |-------~~~~~~~~
# //.-~~~--\
#
# ---------------- If You Are Not Goot At CMake ----------------
# ---[ Dependencies
if (BUILD_PYTHON_API)
include(${PROJECT_SOURCE_DIR}/../CMake/FindPythonLibs.cmake)
include(${PROJECT_SOURCE_DIR}/../CMake/FindNumPy.cmake)
endif()
if (WITH_CUDA)
find_package(CUDA REQUIRED)
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "C++11 support has been enabled by default.")
# ---[ Config types
set(CMAKE_BUILD_TYPE Release CACHE STRING "set build type to release")
set(CMAKE_CONFIGURATION_TYPES Release CACHE STRING "set build type to release" FORCE)
# ---[ Includes
include_directories(${THIRD_PARTY_DIR}/eigen)
include_directories(${THIRD_PARTY_DIR}/protobuf/include)
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/src)
if(APPLE)
include_directories(/usr/local/include)
endif()
if (BUILD_PYTHON_API)
include_directories(${PYTHON_INCLUDE_DIRS})
include_directories(${NUMPY_INCLUDE_DIR})
include_directories(${THIRD_PARTY_DIR}/pybind11/include)
endif()
if (WITH_CUDA)
include_directories(${CUDA_INCLUDE_DIRS})
include_directories(${THIRD_PARTY_DIR}/cub)
endif()
if (WITH_CUDNN)
include_directories(${THIRD_PARTY_DIR}/cudnn/include)
endif()
if (WITH_MPI)
include_directories(${THIRD_PARTY_DIR}/mpi/include)
endif()
# ---[ Lib Directories
list(APPEND THIRD_PARTY_LIBRARY_DIRS ${THIRD_PARTY_DIR}/protobuf/lib)
if(APPLE)
list(APPEND THIRD_PARTY_LIBRARY_DIRS /usr/local/lib)
endif()
if (WITH_CUDA)
list(APPEND THIRD_PARTY_LIBRARY_DIRS ${CUDA_TOOLKIT_ROOT_DIR}/lib)
list(APPEND THIRD_PARTY_LIBRARY_DIRS ${CUDA_TOOLKIT_ROOT_DIR}/lib64)
list(APPEND THIRD_PARTY_LIBRARY_DIRS ${CUDA_TOOLKIT_ROOT_DIR}/lib/x64)
endif()
if (WITH_CUDNN)
list(APPEND THIRD_PARTY_LIBRARY_DIRS ${THIRD_PARTY_DIR}/cudnn/lib)
list(APPEND THIRD_PARTY_LIBRARY_DIRS ${THIRD_PARTY_DIR}/cudnn/lib64)
list(APPEND THIRD_PARTY_LIBRARY_DIRS ${THIRD_PARTY_DIR}/cudnn/lib/x64)
endif()
if (WITH_MPI)
list(APPEND THIRD_PARTY_LIBRARY_DIRS ${THIRD_PARTY_DIR}/mpi/lib)
endif()
link_directories(${THIRD_PARTY_LIBRARY_DIRS})
# ---[ Install
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR} CACHE STRING "set install prefix" FORCE)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${THIRD_PARTY_LIBRARY_DIRS})
# ---[ Defines
if (BUILD_PYTHON_API)
ADD_DEFINITIONS(-DWITH_PYTHON)
if (${PYTHON_VERSION_MAJOR} STREQUAL "2")
message(STATUS "Use Python2 [Optional]")
elseif (${PYTHON_VERSION_MAJOR} STREQUAL "3")
message(STATUS "Use Python3 [Optional]")
add_definitions(-DWITH_PYTHON3)
else()
message("Invalid version of Python(Detected ${PYTHON_VERSION_STRING})")
message(FATAL_ERROR "Do you set PYTHON_EXECUTABLE correctly?")
endif()
endif()
if (WITH_CUDA)
add_definitions(-DWITH_CUDA)
message(STATUS "Use CUDA [Optional]")
endif()
if (WITH_CUDNN)
add_definitions(-DWITH_CUDNN)
message(STATUS "Use CUDNN [Optional]")
endif()
if (WITH_OMP)
ADD_DEFINITIONS(-DWITH_OMP)
message(STATUS "Use OpenMP [Optional]")
endif()
if (WITH_MPI)
add_definitions(-DWITH_MPI)
message(STATUS "Use MPI [Optional]")
endif()
if (WITH_NCCL)
add_definitions(-DWITH_NCCL)
message(STATUS "Use NCCL [Optional]")
endif()
# ---[ Flags
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} ${CUDA_ARCH}")
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /wd4244 /wd4800 /wd4819 /wd4996")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler \"/wd 4800 /wd 4819\"")
string(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "/O2" "/Ox" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
if (WITH_OMP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /openmp")
endif()
endif()
if(UNIX)
if(APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -fPIC -O3 -m64 -std=c++11")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s -fPIC -O3 -m64 -std=c++11")
endif()
if (WITH_OMP AND (NOT APPLE))
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
endif()
endif()
# ---[ Warnings
# ---[ Commands
# ~ Protobuf
set(PROTO_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src/proto)
file(GLOB_RECURSE PROTO_FILES ${PROTO_SOURCE_DIR}/*.proto)
foreach(PROTO_FILE ${PROTO_FILES})
message(STATUS "Generate Proto Files (ref: " ${PROTO_FILE} ")")
execute_process(COMMAND ${PROTOC_EXECUTABLE} -I=${PROTO_SOURCE_DIR} --cpp_out=${PROTO_SOURCE_DIR} ${PROTO_FILE})
endforeach()
# ---[ Subdirectories
if (BUILD_PYTHON_API)
add_subdirectory(modules/python)
endif()
if (BUILD_CXX_API)
add_subdirectory(modules/cxx)
endif()
/*!
* Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
*
* Licensed under the BSD 2-Clause License.
* You should have received a copy of the BSD 2-Clause License
* along with the software. If not, See,
*
* <https://opensource.org/licenses/BSD-2-Clause>
*
* ------------------------------------------------------------
*/
#ifndef DRAGON_CORE_GRAPH_GRADIENT_H_
#define DRAGON_CORE_GRAPH_GRADIENT_H_
#include "core/common.h"
namespace dragon {
class GraphGradientMaker {
public:
GraphGradientMaker()
: cur_op_idx_(0) {}
void Make(
const vector<OperatorDef*>& forward_def,
const vector<string>& targets,
GraphDef& new_def);
void Make(
const GraphDef& forward_def,
GraphDef& backward_def);
GraphDef Share(const GraphDef& input_def);
void SetTerms(const Map<string, string>& terms) { terms_ = terms; }
void SetOperatorPrefix(const string& prefix) { op_prefix_ = prefix; }
void SetOperatorSuffix(const string& suffix) { op_suffix_ = suffix; }
void AddExternalGrad(const string& name) { external_grads_.insert(name); }
void AddIgnoreGrad(const string& name) { ignore_grads_.insert(name); }
private:
bool CheckGrad(
const OperatorDef& forward_op,
const Set<string>& targets,
vector<pair<string, int>>& gen_grads);
string GetOperatorName();
Map<string, string> terms_, inputs_to_grads_;
Set<string> blacklist_set_, external_grads_, ignore_grads_;
string op_prefix_, op_suffix_;
int cur_op_idx_;
};
} // namespace dragon
#endif // DRAGON_CORE_GRAPH_GRADIENT_H_
\ No newline at end of file
/*!
* Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
*
* Licensed under the BSD 2-Clause License.
* You should have received a copy of the BSD 2-Clause License
* along with the software. If not, See,
*
* <https://opensource.org/licenses/BSD-2-Clause>
*
* ------------------------------------------------------------
*/
#ifndef DRAGON_CORE_MIXEDMEM_H_
#define DRAGON_CORE_MIXEDMEM_H_
#include "core/context.h"
#include "core/context_cuda.h"
#include "core/context_cnml.h"
namespace dragon {
typedef enum {
NCHW,
NHWC,
} StorageOrder;
class MixedMemory {
public:
typedef enum {
/*! \brief Initial state */
UNINITIALIZED,
/*! \brief Memory could be modified by CPUContext last time */
STATE_AT_CPU,
/*! \brief Memory could be modified by CUDAContext last time */
STATE_AT_CUDA,
/*! \brief Memory could be modified by CNMLContext last time */
STATE_AT_CNML,
/*! \brief Host and Device now hold the same contents */
SYNCED,
} State;
/*! \brief Default Constructor */
MixedMemory() : cpu_ptr_(nullptr),
cuda_ptr_(nullptr), cnml_ptr_(nullptr) {}
/*! \brief Constructor with the known meta and size */
MixedMemory(const TypeMeta& meta, size_t nbytes)
: meta_(meta), nbytes_(nbytes), cpu_ptr_(nullptr),
cuda_ptr_(nullptr), cnml_ptr_(nullptr) {}
/*! \brief Deconstructor */
~MixedMemory();
/*! \brief Return the const data pointer on CPUContext */
const void* cpu_data(size_t nbytes = 0);
/*! \brief Return the const data pointer on CUDAContext */
const void* cuda_data(size_t nbytes = 0);
/*! \brief Return the const data pointer on CNMLContext */
const void* cnml_data();
/*! \brief Return the mutable data pointer on CPUContext */
void* mutable_cpu_data(size_t nbytes = 0);
/*! \brief Return the mutable data pointer on CUDAContext */
void* mutable_cuda_data(size_t nbytes = 0);
/*! \brief Return the mutable data pointer on CNMLContext */
void* mutable_cnml_data();
/*! \brief Allocate the mlu devive memory */
void* malloc_cnml_data();
/*! \brief Copy the mlu device memory to the host */
void fetch_cnml_data(void** data);
/*! \brief Return the binding CNML cpu tensor */
cnmlCpuTensor_t& cnml_cpu_tensor();
/*! \brief Return the binding CNML mlu tensor */
cnmlTensor_t& cnml_mlu_tensor();
/*! \brief Set the cpu data pointer from external context */
void set_cpu_data(void* cpu_ptr, size_t nbytes);
/*! \brief Switch to the specified device */
void SwitchToDevice(int device_id);
/*! \brief Switch to the specified cuda device */
void SwitchToCUDADevice(int device_id);
/*! \brief Return the total bytes of this memory */
size_t nbytes() const { return nbytes_; }
/*! \brief Return the chunks of this memory */
size_t nchunks() const { return nchunks_; }
/*! \brief Set the chunks of this memory */
void set_nchunks(size_t nchunks) { nchunks_ = nchunks; }
/*! \brief Return the state of this memory */
State state() const { return state_; }
/*! \brief Return or Set the storage order */
StorageOrder order() const { return order_; }
/*! \brief Set the storage order */
void set_order(StorageOrder order) { order_ = order; }
/*! \brief Return the device id of the memory on device */
int device_id() const { return ptr_device_; }
/*! \brief Return a string to describe the internal structure */
const Map<string, string> info() const;
/*! \brief Control the state machine to CPUContext */
void ToCPU(size_t nbytes = 0);
/*! \brief Control the state machine to CUDAContext */
void ToCUDA(size_t nbytes = 0);
private:
/*! \brief The type meta to call the deconstructor */
TypeMeta meta_;
/*! \brief The number of total bytes */
size_t nbytes_ = 0, nchunks_ = 1;
/*! \brief The optional storage order */
StorageOrder order_ = NCHW;
/*! \brief Current memory status indicator */
State state_ = UNINITIALIZED;
/*! \brief Data pointers */
void* cpu_ptr_, *cuda_ptr_, *cnml_ptr_;
/*! \brief Whether this memory owns the cpu data pointer */
int own_cpu_ptr_ = 1;
/*! \brief Store the device id for some data pointers */
int ptr_device_ = 0;
/*! \brief Binding cpu tensor for CAMBRICON's CNML Library */
cnmlCpuTensor_t cnml_cpu_tensor_ = nullptr;
/*! \brief Binding mlu tensor for CAMBRICON's CNML Library */
cnmlTensor_t cnml_mlu_tensor_ = nullptr;
};
} // namespace dragon
#endif // DRAGON_CORE_MIXEDMEM_H_
\ No newline at end of file
/*!
* Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
*
* Licensed under the BSD 2-Clause License.
* You should have received a copy of the BSD 2-Clause License
* along with the software. If not, See,
*
* <https://opensource.org/licenses/BSD-2-Clause>
*
* ------------------------------------------------------------
*/
#ifndef DRAGON_CORE_TYPES_H_
#define DRAGON_CORE_TYPES_H_
#include <cstdint>
#include <vector>
#include <unordered_map>
#include "core/typeid.h"
namespace dragon {
typedef std::vector<int> vec32_t;
typedef std::vector<int64_t> vec64_t;
#ifdef _MSC_VER
typedef struct __declspec(align(2)) {
unsigned short x;
} float16;
#else
typedef struct {
unsigned short x;
} __attribute__((aligned(2))) float16;
#endif
inline const TypeMeta& TypeStringToMeta(
const std::string& str_type) {
static std::unordered_map<std::string, TypeMeta>
s2m_type_map {
{ "bool", TypeMeta::Make<bool>() },
{ "int8", TypeMeta::Make<int8_t>() },
{ "uint8", TypeMeta::Make<uint8_t>() },
{ "int32", TypeMeta::Make<int>() },
{ "int64", TypeMeta::Make<int64_t>() },
{ "float16", TypeMeta::Make<float16>() },
{ "float32", TypeMeta::Make<float>() },
{ "float64", TypeMeta::Make<double>() },
};
static TypeMeta unknown_type;
return s2m_type_map.count(str_type) ?
s2m_type_map[str_type] : unknown_type;
}
inline const std::string TypeMetaToString(
const TypeMeta& meta) {
static std::unordered_map<TypeId, std::string>
m2s_type_map {
{ TypeMeta::Id<bool>(), "bool" },
{ TypeMeta::Id<int8_t>(), "int8" },
{ TypeMeta::Id<uint8_t>(), "uint8" },
{ TypeMeta::Id<int>(), "int32" },
{ TypeMeta::Id<int64_t>(), "int64" },
{ TypeMeta::Id<float16>(), "float16" },
{ TypeMeta::Id<float>(), "float32" },
{ TypeMeta::Id<double>(), "float64", },
};
return m2s_type_map.count(meta.id()) ?
m2s_type_map[meta.id()] : "unknown";
}
template<typename T>
inline const std::string TypeToString() {
return TypeMetaToString(TypeMeta::Make<T>());
}
} // namespace dragon
#endif // DRAGON_CORE_TYPES_H_
\ No newline at end of file
/*!
* Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
*
* Licensed under the BSD 2-Clause License.
* You should have received a copy of the BSD 2-Clause License
* along with the software. If not, See,
*
* <https://opensource.org/licenses/BSD-2-Clause>
*
* ------------------------------------------------------------
*/
#ifndef DRAGON_CORE_WORKSPACE_H_
#define DRAGON_CORE_WORKSPACE_H_
#include "core/graph.h"
namespace dragon {
class Workspace {
public:
typedef Map<string, Map<string, int64_t>> DummyNameMap;
typedef Map<string, unique_ptr<Tensor>> TensorMap;
typedef Map<string, string> TensorAliasMap;
typedef Map<string, TensorFillerProto> TensorFillerMap;
typedef Map<string, unique_ptr<OperatorBase>> OperatorMap;
typedef Map<string, unique_ptr<GraphBase>> GraphMap;
/*! \brief Constructor */
Workspace(const string& name) : name_(name) { Initialize(); }
/*! \brief Return the name of this workspace */
const string& name() { return name_; }
/*! \brief Return the name of stored tensors */
vector<string> tensors() const;
/*! \brief Return the name of stored graphs */
vector<string> graphs() const;
/*! \brief Create some internal tensors */
void Initialize();
/*! \brief Destory all the tensors */
void Clear();
/*! \brief Merge from a external workspace */
void MergeFrom(Workspace*);
/*! \brief Query the real name of specified tensor */
string GetTensorName(const string&) const;
/*! \brief Try to serach the specified tensor in this workspace */
Tensor* TryGetTensor(const string&, bool = true) const;
/*! \brief Whether the specified tensor is in this workspace */
bool HasTensor(const string& name, bool use_remote = true) const {
return TryGetTensor(name, use_remote) ? true : false;
}
/*! \brief Create the specified tensor */
Tensor* CreateTensor(const string&);
/*! \brief Return the specified tensor */
Tensor* GetTensor(const string&, bool = true) const;
/*! \brief Reset the specified tensor */
void ResetTensor(const string&);
/* \brief Whether the specified filler is in this workspace */
bool HasFiller(const string&, bool = true) const;
/*! \brief Create the specified filler */
void CreateFiller(const TensorFillerProto&);
/*! \brief Return the specified filler */
const TensorFillerProto* GetFiller(const string&) const;
/*! \brief Create temporal data segments */
template <class Context>
vector<void*> data(const vector<size_t>& segments) {
int64_t nbytes = 0;
vector<void*> ret(segments.size());
for (auto& segment : segments) nbytes += (int64_t)segment;
auto* T = CreateTensor("/share/data")->Reshape({ nbytes });
ret[0] = T->template mutable_data<uint8_t, Context>();
for (int i = 1; i < segments.size(); i++)
ret[i] = (uint8_t*)ret[i - 1] + segments[i - 1];
return ret;
}
/*! \brief Create temporal cache segments with the specified type */
template <typename T, class Context>
vector<T*> data(const vector<int64_t>& segments) {
vector<size_t> segments_in_byte;
vector<T*> ret(segments.size());
for (const auto& e : segments)
segments_in_byte.emplace_back(e * sizeof(T));
auto ret_in_byte = data<Context>(segments_in_byte);
for (int i = 0; i < segments.size(); i++)
ret[i] = (T*)ret_in_byte[i];
return ret;
}
/*! \brief Create a operator in this workspace */
OperatorBase* CreateOperator(const OperatorDef&);
/*! \brief Run the specified persistent operator */
void RunOperator(const OperatorDef&);
/*! \brief Try to run the operator in a adaptive mode */
void RunOperatorOnce(const OperatorDef&);
/*! \brief Create a Graph in this workspace */
GraphBase* CreateGraph(const GraphDef&);
/*! \brief Run the specifed graph by name and rules */
void RunGraph(
const string& graph_name,
const string& include,
const string& exclude,
int stream_id = 0);
/* \brief Set an alias for the tensor */
bool SetTensorAlias(const string& name, const string& alias);
/* \brief Return a unique dummy name within this workspace */
string GetDummyName(
const string& base_name,
const string& suffix,
const string& domain = "",
const bool zero_based = true);
private:
/*! \brief The unique workspace name */
string name_;
/*! \brief The dummy name indices */
DummyNameMap dummy_name_map_;
/*! \brief Store the created tensors */
TensorMap tensor_map_;
/*! \brief Store the registered tensor fillers */
TensorFillerMap tensor_filler_map_;
/*! \brief Store the proxy name of tensors */
TensorAliasMap tensor_alias_map_;
/*! \brief Store the registered operators for dynamic graph */
OperatorMap operator_map_;
/*! \brief Store the registered graphs for static graph */
GraphMap graph_map_;
/*! \brief Store the remote workspaces */
vector<Workspace*> remote_workspaces_;
};
} // namespace dragon
#endif // DRAGON_CORE_WORKSPACE_H_
\ No newline at end of file
/*!
* Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
*
* Licensed under the BSD 2-Clause License.
* You should have received a copy of the BSD 2-Clause License
* along with the software. If not, See,
*
* <https://opensource.org/licenses/BSD-2-Clause>
*
* ------------------------------------------------------------
*/
#ifndef DRAGON_OPERATORS_ARITHMETIC_AFFINE_OP_H_
#define DRAGON_OPERATORS_ARITHMETIC_AFFINE_OP_H_
#include "core/operator.h"
namespace dragon {
template <class Context>
class AffineOp final : public Operator<Context> {
public:
AffineOp(const OperatorDef& def, Workspace* ws)
: Operator<Context>(def, ws),
axis_(OpArg<int64_t>("axis", 1)),
num_axes_(OpArg<int64_t>("num_axes", 1)) {}
USE_OPERATOR_FUNCTIONS;
void RunOnDevice() override;
template <typename T> void RunImpl();
protected:
int64_t outer_dim_, inner_dim_;
int64_t axis_, num_axes_, scale_dim_;
};
template <class Context>
class AffineGradientOp final : public Operator<Context> {
public:
AffineGradientOp(const OperatorDef& def, Workspace* ws)
: Operator<Context>(def, ws),
axis_(OpArg<int64_t>("axis", 1)),
num_axes_(OpArg<int64_t>("num_axes", 1)) {}
USE_OPERATOR_FUNCTIONS;
void RunOnDevice() override;
template <typename T> void Reduce(T* x, T* y);
template <typename T> void RunImpl();
protected:
int64_t axis_, num_axes_;
int64_t outer_dim_, inner_dim_;
int64_t scale_dim_, reduce_dim_, dim_;
};
#ifdef WITH_CUDNN
#if CUDNN_VERSION_MIN(6, 0, 0)
template <class Context>
class CuDNNAffineOpBase : public Operator<Context> {
public:
CuDNNAffineOpBase(const OperatorDef& def, Workspace* ws)
: Operator<Context>(def, ws),
axis_(OpArg<int64_t>("axis", 1)),
num_axes_(OpArg<int64_t>("num_axes", 1)) {
CuDNNCreateTensorDesc(&input_desc_);
CuDNNCreateTensorDesc(&param_desc_);
CUDNN_CHECK(cudnnCreateOpTensorDescriptor(&mul_op_));
CUDNN_CHECK(cudnnCreateOpTensorDescriptor(&add_op_));
CUDNN_CHECK(cudnnCreateReduceTensorDescriptor(&reduce_desc_));
}
USE_OPERATOR_FUNCTIONS;
virtual ~CuDNNAffineOpBase() {
CuDNNDestroyTensorDesc(&input_desc_);
CuDNNDestroyTensorDesc(&param_desc_);
CUDNN_CHECK(cudnnDestroyOpTensorDescriptor(mul_op_));
CUDNN_CHECK(cudnnDestroyOpTensorDescriptor(add_op_));
CUDNN_CHECK(cudnnDestroyReduceTensorDescriptor(reduce_desc_));
}
template <typename T>
void ResetDesc(const Tensor& X);
int64_t axis_, num_axes_;
cudnnTensorDescriptor_t input_desc_, param_desc_;
cudnnOpTensorDescriptor_t mul_op_, add_op_;
cudnnReduceTensorDescriptor_t reduce_desc_;
};
#define USE_CUDNN_AFFINE_FUCNTIONS \
USE_OPERATOR_FUNCTIONS; \
using CuDNNAffineOpBase<Context>::axis_; \
using CuDNNAffineOpBase<Context>::num_axes_; \
using CuDNNAffineOpBase<Context>::input_desc_; \
using CuDNNAffineOpBase<Context>::param_desc_; \
using CuDNNAffineOpBase<Context>::mul_op_; \
using CuDNNAffineOpBase<Context>::add_op_; \
using CuDNNAffineOpBase<Context>::reduce_desc_
template <class Context>
class CuDNNAffineOp final : public CuDNNAffineOpBase<Context> {
public:
CuDNNAffineOp(const OperatorDef& def, Workspace* ws)
: CuDNNAffineOpBase<Context>(def, ws) {}
void RunOnDevice() override;
template <typename DT, typename CT> void RunImpl();
protected:
USE_CUDNN_AFFINE_FUCNTIONS;
};
template <class Context>
class CuDNNAffineGradientOp final
: public CuDNNAffineOpBase<Context> {
public:
CuDNNAffineGradientOp(
const OperatorDef& def,
Workspace* ws)
: CuDNNAffineOpBase<Context>(def, ws) {}
void RunOnDevice() override;
template <typename DT, typename CT>
void CuDNNReduce(DT* x, DT* y);
template <typename T> void Reduce(T* x, T* y);
template <typename DT, typename CT> void RunImpl();
protected:
USE_CUDNN_AFFINE_FUCNTIONS;
int64_t outer_dim_, inner_dim_;
int64_t scale_dim_, dim_, reduce_dim_;
};
#endif
#endif // WITH_CUDNN
} // namespace dragon
#endif // DRAGON_OPERATORS_ARITHMETIC_AFFINE_OP_H_
\ No newline at end of file
/*!
* Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
*
* Licensed under the BSD 2-Clause License.
* You should have received a copy of the BSD 2-Clause License
* along with the software. If not, See,
*
* <https://opensource.org/licenses/BSD-2-Clause>
*
* ------------------------------------------------------------
*/
#ifndef DRAGON_OPERATORS_ARITHMETIC_ELTWISE_OP_H_
#define DRAGON_OPERATORS_ARITHMETIC_ELTWISE_OP_H_
#include "core/operator.h"
namespace dragon {
template <class Context>
class EltwiseOp final : public Operator<Context> {
public:
EltwiseOp(const OperatorDef& def, Workspace* ws)
: Operator<Context>(def, ws),
coef_(OpArgs<float>("coef")),
operation_(OpArg<string>("operation", "SUM")) {
// Check the number of coeffients
if (coef_.size() > 0) {
CHECK_EQ(coef_.size(), XSize())
<< "\nOp has " << XSize() << " inputs, "
<< "while providing " << coef_.size() << " coefs.";
} else {
coef_.resize((size_t)XSize(), 1.f);
}
// Compute the alpha for product operation
for (auto e : coef_) { if (e != 1.f) alpha_ *= e; }
}
USE_OPERATOR_FUNCTIONS;
void RunOnDevice() override;
template <typename T> void RunImpl();
template <typename T> void SumRunImpl();
template <typename T> void ProdRunImpl();
protected:
string operation_;
float alpha_ = 1.f;
vector<float> coef_;
};
template <class Context>
class EltwiseGradientOp final : public Operator<Context> {
public:
EltwiseGradientOp(const OperatorDef& def, Workspace* ws)
: Operator<Context>(def, ws),
coef_(OpArgs<float>("coef")),
operation_(OpArg<string>("operation", "SUM")) {
if (coef_.size() > 0) {
CHECK_EQ(coef_.size(), YSize())
<< "\nOp has " << YSize() << " inputs, "
<< "while providing " << coef_.size() << " coefs.";
} else {
coef_.resize(YSize(), 1.f);
}
// Compute the alpha for product operation
for (auto e : coef_) { if (e != 1.f) alpha_ *= e; }
}
USE_OPERATOR_FUNCTIONS;
void RunOnDevice() override;
template <typename T> void RunImpl();
template <typename T> void SumRunImpl();
template <typename T> void ProdRunImpl();
protected:
string operation_;
float alpha_ = 1.f;
vector<float> coef_;
};
} // namespace dragon
#endif // DRAGON_OPERATORS_ARITHMETIC_ELTWISE_OP_H_
\ No newline at end of file
/*!
* Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
*
* Licensed under the BSD 2-Clause License.
* You should have received a copy of the BSD 2-Clause License
* along with the software. If not, See,
*
* <https://opensource.org/licenses/BSD-2-Clause>
*
* ------------------------------------------------------------
*/
#ifndef DRAGON_OPERATORS_ARITHMETIC_FULLY_CONNECTED_OP_H_
#define DRAGON_OPERATORS_ARITHMETIC_FULLY_CONNECTED_OP_H_
#include "core/operator.h"
namespace dragon {
template <class Context>
class FullyConnectedOp final : public Operator<Context> {
public:
FullyConnectedOp(const OperatorDef& def, Workspace *ws)
: Operator<Context>(def, ws),
axis_(OpArg<int64_t>("axis", 1)),
N_(OpArg<int64_t>("num_output", 0)),
transW_(OpArg<bool>("transW", true)) {}
USE_OPERATOR_FUNCTIONS;
void RunOnDevice();
template <typename T> void RunImpl();
template <typename T> void TransRunImpl();
template <typename T> void NoTransRunImpl();
protected:
int64_t axis_, transW_, M_, K_, N_;
};
template <class Context>
class FullyConnectedGradientOp
final : public Operator<Context> {
public:
FullyConnectedGradientOp(
const OperatorDef& def,
Workspace* ws)
: Operator<Context>(def, ws),
axis_(OpArg<int64_t>("axis", 1)),
N_(OpArg<int64_t>("num_output", 0)),
transW_(OpArg<bool>("transW", true)) {}
USE_OPERATOR_FUNCTIONS;
void RunOnDevice() override;
template <typename T> void RunImpl();
protected:
int64_t axis_, transW_, M_, K_, N_;
};
} // namespace dragon
#endif // DRAGON_OPERATORS_ARITHMETIC_FULLY_CONNECTED_OP_H_
\ No newline at end of file
/*!
* Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
*
* Licensed under the BSD 2-Clause License.
* You should have received a copy of the BSD 2-Clause License
* along with the software. If not, See,
*
* <https://opensource.org/licenses/BSD-2-Clause>
*
* ------------------------------------------------------------
*/
#ifndef DRAGON_OPERATORS_ARITHMETIC_FUNDAMENTAL_OP_H_
#define DRAGON_OPERATORS_ARITHMETIC_FUNDAMENTAL_OP_H_
#include "core/operator.h"
#include "utils/math_utils.h"
namespace dragon {
#define DECLARE_FUNDAMENTAL_OP(name) \
template <class Context> \
class name##Op final : public Operator<Context> { \
public: \
SIMPLE_CTOR_DTOR(name##Op); \
USE_OPERATOR_FUNCTIONS; \
void RunOnDevice() override; \
template <typename T> void EltwiseRunImpl(); \
template <typename T> void BroadcastRunImpl(int type); \
protected: \
int rows_, cols_; \
};
DECLARE_FUNDAMENTAL_OP(Add);
DECLARE_FUNDAMENTAL_OP(Sub);
DECLARE_FUNDAMENTAL_OP(Mul);
DECLARE_FUNDAMENTAL_OP(Div);
DECLARE_FUNDAMENTAL_OP(RAdd);
DECLARE_FUNDAMENTAL_OP(RSub);
DECLARE_FUNDAMENTAL_OP(RMul);
DECLARE_FUNDAMENTAL_OP(RDiv);
DECLARE_FUNDAMENTAL_OP(AddGradient);
DECLARE_FUNDAMENTAL_OP(SubGradient);
DECLARE_FUNDAMENTAL_OP(MulGradient);
DECLARE_FUNDAMENTAL_OP(DivGradient);
DECLARE_FUNDAMENTAL_OP(RAddGradient);
DECLARE_FUNDAMENTAL_OP(RSubGradient);
DECLARE_FUNDAMENTAL_OP(RMulGradient);
DECLARE_FUNDAMENTAL_OP(RDivGradient);
#define DECLARE_INPUT_DESC \
ws()->CreateTensor(unique_name("A"))->ReshapeLike(X(0)); \
ws()->CreateTensor(unique_name("B"))->ReshapeLike(X(1));
#define DEFINE_INPUT_DESC \
auto* A = ws()->GetTensor(unique_name("A")); \
auto* B = ws()->GetTensor(unique_name("B"));
#define DEFINE_FUNDAMENTAL_TYPED_IMPL(dtype) \
DEFINE_INPUT_DESC; \
if (B->count() < A->count() && \
utils::IsRowwiseBroadcast( \
A->dims(), B->dims(), &rows_, &cols_)) { \
BroadcastRunImpl<dtype>(0); \
} else if (B->count() < A->count() && \
utils::IsColwiseBroadcast( \
A->dims(), B->dims(), &rows_, &cols_)) { \
BroadcastRunImpl<dtype>(1); \
} else if (A->count() == B->count()) { \
EltwiseRunImpl<dtype>(); \
} else { \
LOG(FATAL) << "Could not broadcast with shapes: " \
<< A->DimString() << " and " \
<< B->DimString(); \
}
#define DEFINE_RFUNDAMENTAL_TYPED_IMPL(dtype) \
DEFINE_INPUT_DESC; \
if (B->count() > A->count() && \
utils::IsRowwiseBroadcast( \
A->dims(), B->dims(), &rows_, &cols_)) { \
BroadcastRunImpl<dtype>(2); \
} else if (B->count() > A->count() && \
utils::IsColwiseBroadcast( \
A->dims(), B->dims(), &rows_, &cols_)) { \
BroadcastRunImpl<dtype>(3); \
} else if (A->count() == B->count()) { \
EltwiseRunImpl<dtype>(); \
} else { \
LOG(FATAL) << "Could not broadcast with shapes: " \
<< A->DimString() << " and " \
<< B->DimString(); \
}
#undef DECLARE_FUNDAMENTAL_OP
} // namespace dragon
#endif // DRAGON_OPERATORS_ARITHMETIC_FUNDAMENTAL_OP_H_
\ No newline at end of file
/*!
* Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
*
* Licensed under the BSD 2-Clause License.
* You should have received a copy of the BSD 2-Clause License
* along with the software. If not, See,
*
* <https://opensource.org/licenses/BSD-2-Clause>
*
* ------------------------------------------------------------
*/
#ifndef DRAGON_OPERATORS_ARITHMETIC_MAXIMUM_OP_H_
#define DRAGON_OPERATORS_ARITHMETIC_MAXIMUM_OP_H_
#include "core/operator.h"
namespace dragon {
template <class Context>
class MaximumOp final : public Operator<Context> {
public:
SIMPLE_CTOR_DTOR(MaximumOp);
USE_OPERATOR_FUNCTIONS;
void RunOnDevice() override;
template <typename T> void RunImpl();
template <typename T> void EltwiseRunImpl();
template <typename T> void BroadcastRunImpl();
};
template <class Context>
class MaximumGradientOp final : public Operator<Context> {
public:
SIMPLE_CTOR_DTOR(MaximumGradientOp);
USE_OPERATOR_FUNCTIONS;
void RunOnDevice() override;
template <typename T> void RunImpl();
template <typename T> void EltwiseRunImpl();
template <typename T> void BroadcastRunImpl();
};
} // namespace dragon
#endif // DRAGON_OPERATORS_ARITHMETIC_MAXIMUM_OP_H_
\ No newline at end of file
/*!
* Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
*
* Licensed under the BSD 2-Clause License.
* You should have received a copy of the BSD 2-Clause License
* along with the software. If not, See,
*
* <https://opensource.org/licenses/BSD-2-Clause>
*
* ------------------------------------------------------------
*/
#ifndef DRAGON_OPERATORS_ARITHMETIC_MINIMUM_OP_H_
#define DRAGON_OPERATORS_ARITHMETIC_MINIMUM_OP_H_
#include "core/operator.h"
namespace dragon {
template <class Context>
class MinimumOp final : public Operator<Context> {
public:
SIMPLE_CTOR_DTOR(MinimumOp);
USE_OPERATOR_FUNCTIONS;
void RunOnDevice() override;
template <typename T> void RunImpl();
template <typename T> void EltwiseRunImpl();
template <typename T> void BroadcastRunImpl();
};
template <class Context>
class MinimumGradientOp final : public Operator<Context> {
public:
SIMPLE_CTOR_DTOR(MinimumGradientOp);
USE_OPERATOR_FUNCTIONS;
void RunOnDevice() override;
template <typename T> void RunImpl();
template <typename T> void EltwiseRunImpl();
template <typename T> void BroadcastRunImpl();
};
} // namespace dragon
#endif // DRAGON_OPERATORS_ARITHMETIC_MINIMUM_OP_H_
\ No newline at end of file
/*!
* Copyright (c) 2017-present, SeetaTech, Co.,Ltd.
*
* Licensed under the BSD 2-Clause License.
* You should have received a copy of the BSD 2-Clause License
* along with the software. If not, See,
*
* <https://opensource.org/licenses/BSD-2-Clause>
*
* ------------------------------------------------------------
*/
#ifndef DRAGON_OPERATORS_ARITHMETIC_POW_OP_H_
#define DRAGON_OPERATORS_ARITHMETIC_POW_OP_H_
#include "core/operator.h"
namespace dragon {
template <class Context>
class PowOp final : public Operator<Context> {
public:
PowOp(const OperatorDef& def, Workspace* ws)
: Operator<Context>(def, ws),
scale_(OpArg<float>("scale", 1.f)),
shift_(OpArg<float>("shift", 0.f)),
power_(OpArg<float>("power", 1.f)) {
power_scale_ = power_ * scale_;
}
USE_OPERATOR_FUNCTIONS;
void RunOnDevice() override;
template <typename T> void RunImpl();
protected:
float scale_, shift_;
float power_, power_scale_;
};
template <class Context>
class PowGradientOp final : public Operator<Context> {
public:
PowGradientOp(const OperatorDef& def, Workspace* ws)
: Operator<Context>(def, ws),
scale_(OpArg<float>("scale", 1.f)),
shift_(OpArg<float>("shift", 0.f)),
power_(OpArg<float>("power", 1.f)) {
power_scale_ = power_ * scale_;
}
USE_OPERATOR_FUNCTIONS;
void RunOnDevice() override;
template <typename T> void RunImpl();
protected:
float scale_, shift_;
float power_, power_scale_;
};
} // namespace dragon
#endif // DRAGON_OPERATORS_ARITHMETIC_POW_OP_H_
\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
No preview for this file type
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!