Commit ac5afe2b by xiaotong

new code

parent 47ecabf8
...@@ -206,6 +206,7 @@ void T2TPredictor::Predict(T2TStateBundle * next, XTensor * encoding, XTensor * ...@@ -206,6 +206,7 @@ void T2TPredictor::Predict(T2TStateBundle * next, XTensor * encoding, XTensor *
/* the decoder output of the last position */ /* the decoder output of the last position */
decodingStep = CopyIndexed(decoding, decoding.order - 2, selectSrc, selectTgt); decodingStep = CopyIndexed(decoding, decoding.order - 2, selectSrc, selectTgt);
/* generate the output probabilities */ /* generate the output probabilities */
m->outputLayer->Make(decodingStep, output); m->outputLayer->Make(decodingStep, output);
......
...@@ -158,26 +158,27 @@ void T2TSearch::Score(T2TStateBundle * prev, T2TStateBundle * beam) ...@@ -158,26 +158,27 @@ void T2TSearch::Score(T2TStateBundle * prev, T2TStateBundle * beam)
_SumDim(&prob, &probPathPrev, &score, 0); _SumDim(&prob, &probPathPrev, &score, 0);
InitTensor(&len, &lenPrev); InitTensor(&len, &lenPrev);
InitTensor(&lp, &lenPrev);
_ScaleAndShift(&lenPrev, &len, 1.0F, 1.0F); //_ScaleAndShift(&lenPrev, &len, 1.0F, 1.0F);
/* the GNMT-like length penalty */ /* the GNMT-like length penalty */
lp = T2TLengthPenalizer::GNMT(len, alpha); //lp = T2TLengthPenalizer::GNMT(len, alpha);
lp.Reshape(lp.unitNum); lp.Reshape(lp.unitNum);
/* score = log-prob/lp */ /* score = log-prob/lp */
_DivDim(&score, &lp, &score, 0); //_DivDim(&score, &lp, &score, 0);
InitTensor(&mask, &prev->endMark); InitTensor(&mask, &prev->endMark);
CopyValues(prev->endMark, mask); //CopyValues(prev->endMark, mask);
_ScaleAndShiftMe(&mask, -1e9F); //_ScaleAndShiftMe(&mask, -1e9F);
mask.Reshape(mask.unitNum); mask.Reshape(mask.unitNum);
/* mask the completed hypotheses so that they cannot /* mask the completed hypotheses so that they cannot
be involved in further sorting and beam search. */ be involved in further sorting and beam search. */
_SumDim(&score, &mask, &score, 0); //_SumDim(&score, &mask, &score, 0);
prob.Reshape(order, dims); prob.Reshape(order, dims);
score.Reshape(order, dims); score.Reshape(order, dims);
...@@ -227,9 +228,9 @@ void T2TSearch::Generate(T2TStateBundle * beam) ...@@ -227,9 +228,9 @@ void T2TSearch::Generate(T2TStateBundle * beam)
score.Reshape(order, dimsBeam); score.Reshape(order, dimsBeam);
/* keep the most promissing candidates in the beam */ /* keep the most promissing candidates in the beam */
TopK(score, scoreTopK, index, -1, beamSize); //TopK(score, scoreTopK, index, -1, beamSize);
CopyValues(scoreTopK, preID); CopyValues(index, preID);
int sizeVocab = score.GetDim(-1); int sizeVocab = score.GetDim(-1);
......
...@@ -84,15 +84,18 @@ void KernelAddWithCol(T * a, T * b, T * c, int rowNum, int colNum, int blockSize ...@@ -84,15 +84,18 @@ void KernelAddWithCol(T * a, T * b, T * c, int rowNum, int colNum, int blockSize
int colIndex = blockDim.x * blockIdx.x + threadIdx.x; int colIndex = blockDim.x * blockIdx.x + threadIdx.x;
int row = blockDim.y * blockIdx.y + threadIdx.y; int row = blockDim.y * blockIdx.y + threadIdx.y;
int col = colIndex % colNum; int col = colIndex % blockSize;
int block = colIndex / colNum; int block = colIndex / blockSize;
if(row >= rowNum || block >= blockNum) if(row >= rowNum || block >= blockNum)
return; return;
if(threadIdx.x == 0) if(threadIdx.x == 0){
printf("(%d %d) ", row, block);
bv[threadIdx.y] = b[row]; bv[threadIdx.y] = b[row];
}
/*
__syncthreads(); __syncthreads();
int offset = block * blockSize + row * colNum + col; int offset = block * blockSize + row * colNum + col;
...@@ -100,7 +103,7 @@ void KernelAddWithCol(T * a, T * b, T * c, int rowNum, int colNum, int blockSize ...@@ -100,7 +103,7 @@ void KernelAddWithCol(T * a, T * b, T * c, int rowNum, int colNum, int blockSize
if(betaFired) if(betaFired)
c[offset] = a[offset] + bv[threadIdx.y] * beta; c[offset] = a[offset] + bv[threadIdx.y] * beta;
else else
c[offset] = a[offset] + bv[threadIdx.y]; c[offset] = a[offset] + bv[threadIdx.y];*/
} }
/* /*
......
...@@ -41,7 +41,8 @@ void _CopyValues(const XTensor * s, XTensor * t, XStream * stream) ...@@ -41,7 +41,8 @@ void _CopyValues(const XTensor * s, XTensor * t, XStream * stream)
CheckNTErrors(s != NULL && t != NULL, "The input tensor and output tensor must be nonempty!"); CheckNTErrors(s != NULL && t != NULL, "The input tensor and output tensor must be nonempty!");
CheckNTErrors(s->data != NULL, "Cannot copy an empty data array!"); CheckNTErrors(s->data != NULL, "Cannot copy an empty data array!");
CheckNTErrors(t->data != NULL, "Cannot copy to an empty data array!"); CheckNTErrors(t->data != NULL, "Cannot copy to an empty data array!");
CheckNTErrors(s->unitNum == t->unitNum, "Unmatched data item number!"); CheckNTErrors(s->unitSize == t->unitSize, "Incompatible data types in value copy.");
CheckNTErrors(s->unitNum == t->unitNum, "The data items are be the same.");
if ((s->dataType == X_FLOAT16 && t->dataType == X_FLOAT) || if ((s->dataType == X_FLOAT16 && t->dataType == X_FLOAT) ||
(s->dataType == X_FLOAT && t->dataType == X_FLOAT16)) { (s->dataType == X_FLOAT && t->dataType == X_FLOAT16)) {
...@@ -90,9 +91,9 @@ void _CopyValues(const XTensor * s, const int sBeg, const int sLen, XTensor * t, ...@@ -90,9 +91,9 @@ void _CopyValues(const XTensor * s, const int sBeg, const int sLen, XTensor * t,
CheckNTErrors(s != NULL && t != NULL, "The input tensor and output tensor must be nonempty!"); CheckNTErrors(s != NULL && t != NULL, "The input tensor and output tensor must be nonempty!");
CheckNTErrors(s->data != NULL, "Cannot copy an empty data array!"); CheckNTErrors(s->data != NULL, "Cannot copy an empty data array!");
CheckNTErrors(t->data != NULL, "Cannot copy to an empty data array!"); CheckNTErrors(t->data != NULL, "Cannot copy to an empty data array!");
CheckNTErrors(s->unitSize == t->unitSize, "The input tensors must be of the same unit size!"); CheckNTErrors(s->unitSize == t->unitSize, "Incompatible data types in value copy.");
CheckNTErrors(s->order > sBeg && sBeg >= 0 && sLen <= s->unitNum, "Wrong segment on the source side"); CheckNTErrors(sBeg >= 0 && sBeg + sLen <= s->unitNum, "Wrong segment of the source data array");
CheckNTErrors(t->order > tBeg && tBeg >= 0, "Wrong segment on the target side"); CheckNTErrors(tBeg >= 0 && tBeg + sLen <= t->unitNum, "Wrong segment of the target data array");
if (!s->isSparse && !t->isSparse) { if (!s->isSparse && !t->isSparse) {
XMemCopy((char*)t->data + tBeg * t->unitSize, t->devID, XMemCopy((char*)t->data + tBeg * t->unitSize, t->devID,
......
...@@ -37,10 +37,11 @@ copy a range of elements from a source vector to a target vector ...@@ -37,10 +37,11 @@ copy a range of elements from a source vector to a target vector
*/ */
void _CudaCopyValues(const XTensor * s, XTensor * t, XStream * stream) void _CudaCopyValues(const XTensor * s, XTensor * t, XStream * stream)
{ {
CheckNTErrors((s != NULL && t != NULL), "The input tensor and output tensor must be nonempty!"); CheckNTErrors(s != NULL && t != NULL, "The input tensor and output tensor must be nonempty!");
CheckNTErrors(s->dataType == t->dataType, "Unmatched data type!"); CheckNTErrors(s->dataType == t->dataType, "Unmatched data type!");
CheckNTErrors((s->unitSize == t->unitSize), "Incompatible vectors in value copy."); CheckNTErrors(s->unitSize == t->unitSize, "Incompatible data types in value copy.");
CheckNTErrors((s->denseRatio <= s->denseRatio), "Incompatible vectors in value copy."); CheckNTErrors(s->unitNum == t->unitNum, "The data items are be the same.");
CheckNTErrors(s->denseRatio <= t->denseRatio, "Incompatible vectors in value copy.");
/* dense -> dense */ /* dense -> dense */
if (!s->isSparse && !t->isSparse) { if (!s->isSparse && !t->isSparse) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论