forked from intel-analytics/ipex-llm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request intel-analytics#4 from JerryYanWan/deepspeech
deepspeech2 inference
- Loading branch information
Showing
28 changed files
with
3,019 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
pipeline/src/main/scala/com/intel/analytics/zoo/pipeline/deepspeech2/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
### ds2 model (~387MB): | ||
https://drive.google.com/open?id=0B_s7AwBOnuD-ckRqQWM3WFctZmM | ||
|
||
### sample audio files: | ||
|
||
Please upload your samples audio to HDFS. For instance, hdfs://127.0.0.1:9001/deepspeech/data | ||
|
||
Please save your ds2.model to HDFS. For instance, hdfs://127.0.0.1:9001/deepspeech/data/ds2.model | ||
|
||
### run on clusters | ||
|
||
```shell | ||
./bigdl.sh -- spark-submit --master local[1] \ | ||
--conf spark.driver.memory=20g \ | ||
--conf "spark.serializer=org.apache.spark.serializer.JavaSerializer" \ | ||
--class com.intel.analytics.zoo.pipeline.deepspeech2.example.InferenceEvaluate \ | ||
pipeline-0.1-SNAPSHOT-jar-with-dependencies.jar \ | ||
--host hdfs://127.0.0.1:9001 --path /deepspeech/data | ||
``` |
96 changes: 96 additions & 0 deletions
96
pipeline/src/main/scala/com/intel/analytics/zoo/pipeline/deepspeech2/bigdl.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# Copyright 2016 The BigDL Authors. | ||
# | ||
# Licensed 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 the License. | ||
# | ||
|
||
# | ||
# This script is to set right environment variables for BigDL library. User can use this script to | ||
# invoke command(e.g. spark-submit), like this | ||
# bigdl.sh [options] -- command | ||
# Note that the command should be placed behind the -- symbol. And the options of bigdl should be | ||
# placed before the -- symbol. | ||
# | ||
# User can also source this script, then can run command without the script. Like this | ||
# source bigdl.sh [options] | ||
# command1 | ||
# command2 | ||
# | ||
# Options: | ||
# -c : core number to run program. Note that it will be override by Spark configuration, like | ||
# n of local[n] in Spark local mode, or --executor-cores in Spark cluster mode. So it only | ||
# takes affect when program don't run on Spark. | ||
# | ||
|
||
CMD="" | ||
EXIT_CODE=0 | ||
|
||
set_mkl_blas() { | ||
# TODO: Generate export statements in the build from spark-bigdl.conf | ||
export OMP_NUM_THREADS=1 | ||
export KMP_BLOCKTIME=0 | ||
export OMP_WAIT_POLICY=passive | ||
export DL_ENGINE_TYPE=mklblas | ||
export MKL_DISABLE_FAST_MM=1 | ||
} | ||
|
||
parse() { | ||
while [ $# -gt 0 ]; do | ||
key="$1" | ||
case $key in | ||
-c|--core) | ||
export DL_CORE_NUMBER="$2" | ||
shift 2 | ||
;; | ||
-l|--local) | ||
export BIGDL_LOCAL_MODE="1" | ||
shift 1 | ||
;; | ||
--) | ||
shift | ||
for token in "$@"; do | ||
case "$token" in | ||
*\ * ) | ||
# add quto when there's space in the token | ||
CMD="$CMD '$token'" | ||
;; | ||
*) | ||
CMD="$CMD $token" | ||
;; | ||
esac | ||
done | ||
shift $# # escape from the while loop | ||
;; | ||
*) | ||
echo "Invalid option $key" | ||
shift $# # escape from the while loop | ||
EXIT_CODE=1 | ||
;; | ||
esac | ||
done | ||
} | ||
|
||
parse "$@" | ||
|
||
if [ $EXIT_CODE -ne 0 ]; then | ||
return $EXIT_CODE | ||
fi | ||
|
||
# set the envs based on the mode | ||
set_mkl_blas | ||
|
||
if [ "$CMD" != "" ]; then | ||
eval $CMD | ||
fi |
104 changes: 104 additions & 0 deletions
104
...in/scala/com/intel/analytics/zoo/pipeline/deepspeech2/bigdl/nn/BatchNormalizationDS.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Copyright 2016 The BigDL Authors. | ||
* | ||
* Licensed 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 the License. | ||
*/ | ||
package com.intel.analytics.bigdl.nn | ||
|
||
import com.intel.analytics.bigdl.nn._ | ||
import com.intel.analytics.bigdl.nn.abstractnn.TensorModule | ||
import com.intel.analytics.bigdl.tensor.{DoubleType, FloatType, Tensor} | ||
import com.intel.analytics.bigdl.tensor.TensorNumericMath.TensorNumeric | ||
|
||
import scala.reflect.ClassTag | ||
|
||
@SerialVersionUID( - 467695939363389565L) | ||
class BatchNormalizationDS[@specialized(Float, Double) T: ClassTag]( | ||
nOutput: Int, | ||
eps: Double = 1e-3, | ||
momentum: Double = 0.1, | ||
affine: Boolean = false) | ||
(implicit ev: TensorNumeric[T]) | ||
extends BatchNormalization[T](nOutput, eps, momentum, affine) { | ||
|
||
val batchDim = 0 | ||
val timeDim = 1 | ||
val featDim = 2 | ||
|
||
override def updateOutput(input: Tensor[T]): Tensor[T] = { | ||
require(input.dim == 3, | ||
"In BatchNormalizationBRNN, input should be a 3D tensor, [B, T, D]" + | ||
s"input.dim = ${input.dim}") | ||
val size = input.size() | ||
input.resize(size(batchDim) * size(timeDim), size(featDim)) | ||
output = super.updateOutput(input) | ||
output.resize(size) | ||
input.resize(size) | ||
output | ||
} | ||
|
||
override def backward(input: Tensor[T], gradOutput: Tensor[T]): Tensor[T] = { | ||
val size = input.size() | ||
input.resize(size(batchDim) * size(timeDim), size(featDim)) | ||
gradOutput.resize(size(batchDim) * size(timeDim), size(featDim)) | ||
val result = super.backward(input, gradOutput) | ||
input.resize(size) | ||
gradOutput.resize(size) | ||
result.resize(size) | ||
result | ||
} | ||
|
||
override def updateGradInput(input: Tensor[T], gradOutput: Tensor[T]): Tensor[T] = { | ||
val size = input.size() | ||
input.resize(size(batchDim) * size(timeDim), size(featDim)) | ||
gradOutput.resize(size(batchDim) * size(timeDim), size(featDim)) | ||
gradInput = super.updateGradInput(input, gradOutput) | ||
gradInput.resize(size) | ||
input.resize(size) | ||
gradOutput.resize(size) | ||
gradInput | ||
} | ||
|
||
override def accGradParameters(input: Tensor[T], gradOutput: Tensor[T], scale: Double): Unit = { | ||
val size = input.size() | ||
input.resize(size(batchDim) * size(timeDim), size(featDim)) | ||
gradOutput.resize(size(batchDim) * size(timeDim), size(featDim)) | ||
super.accGradParameters(input, gradOutput) | ||
input.resize(size) | ||
gradOutput.resize(size) | ||
} | ||
|
||
override def toString(): String = s"BatchNormalizationBRNN" | ||
|
||
override def canEqual(other: Any): Boolean = other.isInstanceOf[BatchNormalizationDS[T]] | ||
|
||
override def equals(other: Any): Boolean = other match { | ||
case that: BatchNormalizationDS[T] => | ||
super.equals(that) && | ||
(that canEqual this) | ||
case _ => false | ||
} | ||
|
||
override def hashCode(): Int = { | ||
val state = Seq(super.hashCode(), batchDim, timeDim, featDim) | ||
state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b) | ||
} | ||
} | ||
|
||
object BatchNormalizationDS { | ||
def apply[@specialized(Float, Double) T: ClassTag]( | ||
nOutput: Int, | ||
eps: Double = 1e-5) (implicit ev: TensorNumeric[T]): BatchNormalizationDS[T] = { | ||
new BatchNormalizationDS[T](nOutput, eps) | ||
} | ||
} |
Oops, something went wrong.