Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update BlockMomentumDistributedLearner.h #3501

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions Source/1BitSGD/BlockMomentumDistributedLearner.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,38 +524,40 @@ namespace CNTK
ResetBuffer<double>(i, p);
else if (p->GetDataType() == DataType::Float)
ResetBuffer<float>(i, p);
else if (p->GetDataType() == DataType::Float16)
ResetBuffer<half, float16>(i, p);
else
RuntimeError("Unsupported type.");
}
}

template<class ElemType>
template<class ElemTypeV1, class ElemTypeV2=ElemTypeV1>
void ResetBuffer(size_t index, const NDArrayViewPtr& p)
{
auto data = p->GetMatrix<ElemType>();
auto data = p->GetMatrix<ElemTypeV1>();
if (!m_blockLevelSmoothedGradient[index])
{
// has not been initialized yet
auto pSmoothedGrad = std::make_shared<NDArrayView>(AsDataType<ElemType>(), p->Shape(), AsDeviceDescriptor(data->GetDeviceId()));
pSmoothedGrad->SetValue(static_cast<ElemType>(0));
auto pSmoothedGrad = std::make_shared<NDArrayView>(AsDataType<ElemTypeV2>(), p->Shape(), AsDeviceDescriptor(data->GetDeviceId()));
pSmoothedGrad->SetValue(static_cast<ElemTypeV2>(0));
m_blockLevelSmoothedGradient[index] = pSmoothedGrad;
}

if (!m_prevParameters[index])
{
NDArrayViewPtr newValue = std::make_shared<NDArrayView>(AsDataType<ElemType>(), p->Shape(), AsDeviceDescriptor(data->GetDeviceId()));
std::shared_ptr<Matrix<ElemType>> newData = newValue->GetWritableMatrix<ElemType>();
NDArrayViewPtr newValue = std::make_shared<NDArrayView>(AsDataType<ElemTypeV2>(), p->Shape(), AsDeviceDescriptor(data->GetDeviceId()));
std::shared_ptr<Matrix<ElemTypeV1>> newData = newValue->GetWritableMatrix<ElemTypeV1>();
newData->SetValue(*data);
m_prevParameters[index] = newValue;
}
else
{
m_prevParameters[index]->GetWritableMatrix<ElemType>()->SetValue(*data);
m_prevParameters[index]->GetWritableMatrix<ElemTypeV1>()->SetValue(*data);
}

if (!m_tempBlockGradient[index])
{
m_tempBlockGradient[index] = std::make_shared<NDArrayView>(AsDataType<ElemType>(), p->Shape(), AsDeviceDescriptor(data->GetDeviceId()));
m_tempBlockGradient[index] = std::make_shared<NDArrayView>(AsDataType<ElemTypeV2>(), p->Shape(), AsDeviceDescriptor(data->GetDeviceId()));
}
}

Expand Down
2 changes: 2 additions & 0 deletions Source/CNTKv2LibraryDll/DistributedCommunicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "GPUDataTransferer.h"
#include <numeric>
#include "Utils.h"
#include<iostream>

using namespace Microsoft::MSR::CNTK;

Expand Down Expand Up @@ -732,6 +733,7 @@ namespace CNTK
{
if (m_nccl->IsSupported() && !dataOnCPU)
{
std::cerr << " NCCL fp16 allreduce" << endl;
m_nccl->AllReduce(inputData, outputData, numElements, op);

return;
Expand Down
3 changes: 2 additions & 1 deletion Source/Common/Include/Sequences.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ struct MBLayout
LogicError("GetColumnIndex: t out of sequence bounds.");
if (seq.s > GetNumParallelSequences())
LogicError("GetColumnIndex: seq.s out of sequence bounds."); // can only happen if 'seq' does not come out of our own m_sequences array, which is verboten
ptrdiff_t tIn = (ptrdiff_t)t + seq.tBegin; // shifted time index
//ptrdiff_t tIn = (ptrdiff_t)t + seq.tBegin; // shifted time index
ptrdiff_t tIn = (ptrdiff_t)t + (seq.tBegin > 0 ? seq.tBegin : 0 ); // shifted time index
if (tIn < 0 || (size_t)tIn >= GetNumTimeSteps())
LogicError("GetColumnIndex: Attempted to access a time step that is accessing a portion of a sequence that is not included in current minibatch."); // we may encounter this for truncated BPTT
size_t col = (size_t)tIn * GetNumParallelSequences() + seq.s;
Expand Down
2 changes: 2 additions & 0 deletions bindings/python/cntk/logging/progress_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ def write(self, key, value):
def ___logprint(self, logline):
if self.log_to_file == None:
# to stdout. if distributed, all ranks merge output into stdout
t = time.localtime()
print(str(t.tm_year) + '-' + str(t.tm_mon) + '-' + str(t.tm_mday) + ' ' + str(t.tm_hour) + ':' + str(t.tm_min) + ':' + str(t.tm_sec), end = ' ')
print(logline)
else:
# to named file. if distributed, one file per rank
Expand Down