Skip to content

Commit

Permalink
Merge pull request #813 from chrishkchris/resolve_conflict
Browse files Browse the repository at this point in the history
Update the dev branch before the development
  • Loading branch information
nudles authored Oct 31, 2020
2 parents da67921 + 2da007a commit 207bec2
Show file tree
Hide file tree
Showing 20 changed files with 618 additions and 60 deletions.
25 changes: 15 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@ PROJECT(singa)

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Thirdparty)

include(GetGitRevisionDescription)
git_describe(VERSION --tags --dirty=-d)
string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
#include(GetGitRevisionDescription)
#git_describe(VERSION --tags --dirty=-d)
#string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
#string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
#string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")


SET(PACKAGE_VERSION 3.1.0) # ${VERSION})
SET(VERSION 3.1.0)
SET(SINGA_MAJOR_VERSION 3)
SET(SINGA_MINOR_VERSION 1)
SET(SINGA_PATCH_VERSION 0)
#SET(SINGA_MAJOR_VERSION ${VERSION_MAJOR}) # 0 -
#SET(SINGA_MINOR_VERSION ${VERSION_MINOR}) # 0 - 9
#SET(SINGA_PATCH_VERSION ${VERSION_PATCH}) # 0 - 99


SET(PACKAGE_VERSION ${VERSION})
SET(SINGA_MAJOR_VERSION ${VERSION_MAJOR}) # 0 -
SET(SINGA_MINOR_VERSION ${VERSION_MINOR}) # 0 - 9
SET(SINGA_PATCH_VERSION ${VERSION_PATCH}) # 0 - 99
MATH(EXPR SINGA_VERSION "${SINGA_MAJOR_VERSION} * 1000 + ${SINGA_MINOR_VERSION} * 100 + ${SINGA_PATCH_VERSION}")

message(STATUS "SINGA git Version ${VERSION}")
Expand Down
33 changes: 33 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ SINGA bundles the following under Apache License Version 2.0:
examples/onnx/tokenization.py
examples/onnx/run_onnx_squad.py
examples/onnx/inputs.json
examples/onnx/gpt2/requirements.txt
examples/onnx/ro_bert_a/requirements.txt

# Copyright 2018 The Google AI Language Team Authors.
#
Expand All @@ -526,3 +528,34 @@ examples/onnx/inputs.json
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


===============================================================================
SINGA bundles the following under new BSD 3-clause license:
tool/docker/devel/centos6/cuda10/cuda.repo

Copyright (c) 2019,2020 NVIDIA CORPORATION. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of NVIDIA CORPORATION nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

# Apache SINGA

[![Native Ubuntu build status](https://github.com/apache/singa/workflows/Native-Ubuntu/badge.svg)
[![Native Mac build status](https://github.com/apache/singa/workflows/Native-MacOS/badge.svg)
[![conda build status](https://github.com/apache/singa/workflows/conda/badge.svg)
![Native Ubuntu build status](https://github.com/apache/singa/workflows/Native-Ubuntu/badge.svg)
![Native Mac build status](https://github.com/apache/singa/workflows/Native-MacOS/badge.svg)
![conda build status](https://github.com/apache/singa/workflows/conda/badge.svg)
[![Documentation Status](https://readthedocs.org/projects/apache-singa/badge/?version=latest)](https://apache-singa.readthedocs.io/en/latest/?badge=latest)
![License](http://img.shields.io/:license-Apache%202.0-blue.svg)
[![Follow Apache SINGA on Twitter](https://img.shields.io/twitter/follow/apachesinga.svg?style=social&label=Follow)](https://twitter.com/ApacheSinga)
Expand All @@ -35,7 +35,7 @@ Distributed deep learning system

## Quick Start

* [Installation](doc/en/docs/installation.md)
* [Installation](http://singa.apache.org/docs/installation/)
* [Examples](examples)

## Issues
Expand Down
41 changes: 41 additions & 0 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
Release Notes - SINGA - Version singa-3.1.0

SINGA is a distributed deep learning library.

This release includes following changes:

* Tensor core:
* Support tensor transformation (reshape, transpose) for tensors up to 6 dimensions.
* Implement traverse_unary_transform in Cuda backend, which is similar to CPP backend one.

* Add new tensor operators into the autograd module, including
CosSim, DepthToSpace, Embedding, Erf, Expand, Floor, Pad, Round, Rounde, SpaceToDepth, UpSample, Where.
The corresponding ONNX operators are thus supported by SINGA.

* Add Embedding and Gemm into the layer module.

* Add SGD operators to opt module, including RMSProp, Adam, and AdaGrad.

* Extend the sonnx module to support
DenseNet121, ShuffleNetv1, ShuffleNetv2, SqueezeNet, VGG19, GPT2, and RoBERTa,

* Reconstruct sonnx to
* Support creating operators from both layer and autograd.
* Re-write SingaRep to provide a more powerful intermediate representation of SINGA.
* Add a SONNXModel which implements from Model to provide uniform API and features.

* Add one example that trains a BiLSTM model over the InsuranceQA data.

* Replace the Travis CI with Github workflow. Add quality and coverage management.

* Add compiling and packaging scripts to creat wheel packages for distribution.

* Fix bugs
* Fix IMDB LSTM model example training script.
* Fix Tensor operation Mult on Broadcasting use cases.
* Gaussian function on Tensor now can run on Tensor with odd size.
* Updated a testing helper function gradients() in autograd to lookup param gradient by param python object id for testing purpose.


----------------------------------------------------------------------------------------------

Release Notes - SINGA - Version singa-3.0.0

SINGA is a distributed deep learning library.
Expand Down
4 changes: 2 additions & 2 deletions examples/cnn/train_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ def run(global_rank,
os.path.abspath(inspect.getfile(inspect.currentframe())))
parent = os.path.dirname(current)
sys.path.insert(0, parent)
from mlp import module
model = module.create_model(data_size=data_size,
from mlp import model
model = model.create_model(data_size=data_size,
num_classes=num_classes)

# For distributed training, sequential gives better performance
Expand Down
116 changes: 116 additions & 0 deletions examples/onnx/densenet121.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under th

import os
import numpy as np
from PIL import Image

from singa import device
from singa import tensor
from singa import autograd
from singa import sonnx
import onnx
from utils import download_model, update_batch_size, check_exist_or_download

import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)-15s %(message)s')


def preprocess(img):
img = img.resize((256, 256))
img = img.crop((16, 16, 240, 240))
img = np.array(img).astype(np.float32) / 255.
img = np.rollaxis(img, 2, 0)
for channel, mean, std in zip(range(3), [0.485, 0.456, 0.406],
[0.229, 0.224, 0.225]):
img[channel, :, :] -= mean
img[channel, :, :] /= std
img = np.expand_dims(img, axis=0)
return img


def get_image_labe():
# download label
label_url = 'https://s3.amazonaws.com/onnx-model-zoo/synset.txt'
with open(check_exist_or_download(label_url), 'r') as f:
labels = [l.rstrip() for l in f]

# download image
image_url = 'https://s3.amazonaws.com/model-server/inputs/kitten.jpg'
img = Image.open(check_exist_or_download(image_url))
return img, labels


class Infer:

def __init__(self, sg_ir):
self.sg_ir = sg_ir
for idx, tens in sg_ir.tensor_map.items():
# allow the tensors to be updated
tens.requires_grad = True
tens.stores_grad = True
sg_ir.tensor_map[idx] = tens

def forward(self, x):
return sg_ir.run([x])[0]


if __name__ == "__main__":
url = 'https://s3.amazonaws.com/download.onnx/models/opset_9/densenet121.tar.gz'
download_dir = '/tmp/'
model_path = os.path.join(download_dir, 'densenet121', 'model.onnx')

logging.info("onnx load model...")
download_model(url)
onnx_model = onnx.load(model_path)

# set batch size
onnx_model = update_batch_size(onnx_model, 1)

# prepare the model
logging.info("prepare model...")
dev = device.create_cuda_gpu()
sg_ir = sonnx.prepare(onnx_model, device=dev)
autograd.training = False
model = Infer(sg_ir)

# verifty the test
# from utils import load_dataset
# inputs, ref_outputs = load_dataset(
# os.path.join('/tmp', 'densenet121', 'test_data_set_0'))
# x_batch = tensor.Tensor(device=dev, data=inputs[0])
# outputs = model.forward(x_batch)
# for ref_o, o in zip(ref_outputs, outputs):
# np.testing.assert_almost_equal(ref_o, tensor.to_numpy(o), 4)

# inference
logging.info("preprocessing...")
img, labels = get_image_labe()
img = preprocess(img)

logging.info("model running...")
x_batch = tensor.Tensor(device=dev, data=img)
y = model.forward(x_batch)

logging.info("postprocessing...")
y = tensor.softmax(y)
scores = tensor.to_numpy(y)
scores = np.squeeze(scores)
a = np.argsort(scores)[::-1]
for i in a[0:5]:
logging.info('class=%s ; probability=%f' % (labels[i], scores[i]))
2 changes: 1 addition & 1 deletion examples/onnx/gpt2/gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ def train_one_batch(self, x, y):
y = tensor.Tensor(device=dev, data=y)
x = tensor.concatenate([x, y], 2)

text = tokenizer.decode(output)
text = postprocess(output)
print(text)
1 change: 1 addition & 0 deletions examples/onnx/ro_bert_a/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
transformers==2.5.1
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
# under the License.
#


import sys
sys.path.append('/singa/build/python/')

import os
import numpy as np

Expand All @@ -30,6 +26,8 @@
from singa import autograd
import onnx

import sys
sys.path.append(os.path.dirname(__file__) + '/..')
from utils import download_model, check_exist_or_download

import logging
Expand All @@ -45,12 +43,6 @@ def preprocess():
tokens = np.array(tokens)
return tokens.reshape([1, -1]).astype(np.float32)


def postprocess(out):
text = tokenizer.decode(out)
return text


class MyModel(sonnx.SONNXModel):

def __init__(self, onnx_model):
Expand Down
Loading

0 comments on commit 207bec2

Please sign in to comment.