-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* format: refactor * format: fix typos * format: update setup.py * format: update format
- Loading branch information
1 parent
c507e14
commit 2a98d12
Showing
29 changed files
with
420 additions
and
389 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
This file was deleted.
Oops, something went wrong.
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,44 @@ | ||
// Copyright 2019 Amazon Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// 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. | ||
// ============================================================================= | ||
|
||
#ifndef BYTEPS_COMPRESSOR_COMMON_H | ||
#define BYTEPS_COMPRESSOR_COMMON_H | ||
|
||
#include <unordered_map> | ||
|
||
namespace byteps { | ||
namespace common { | ||
namespace compressor { | ||
typedef char byte_t; | ||
/*! | ||
* \brief Tensor type | ||
*/ | ||
typedef struct BPSTensor { | ||
byte_t* data; | ||
size_t size; | ||
int dtype; | ||
|
||
BPSTensor() : data(nullptr), size(0), dtype(0) {} | ||
BPSTensor(byte_t* data, size_t size=0, int dtype=0) | ||
: data(data), size(size), dtype(dtype) {} | ||
} tensor_t; | ||
|
||
using kwargs_t = std::unordered_map<std::string, std::string>; | ||
|
||
} // namespace compressor | ||
} // namespace common | ||
} // namespace byteps | ||
|
||
#endif // BYTEPS_COMPRESSOR_COMMON_H |
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,89 @@ | ||
// Copyright 2019 Amazon Inc. or its affiliates. All Rights Reserved. | ||
// | ||
// 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. | ||
// ============================================================================= | ||
|
||
#ifndef BYTEPS_COMPRESSOR_COMPRESSOR_H | ||
#define BYTEPS_COMPRESSOR_COMPRESSOR_H | ||
|
||
#include <memory> | ||
|
||
#include "../cpu_reducer.h" | ||
#include "common.h" | ||
|
||
namespace byteps { | ||
namespace common { | ||
namespace compressor { | ||
/*! | ||
* \brief Compressor interface used in BytePS core. | ||
*/ | ||
class Compressor { | ||
public: | ||
Compressor(size_t size) | ||
: _size(size), | ||
_buf(new byte_t[size]), | ||
_cpu_reducer(new CpuReducer(nullptr)){}; | ||
virtual ~Compressor() = default; | ||
|
||
/*! | ||
* \brief Compress function | ||
* | ||
* \param grad gradient tensor | ||
* \param compressed compressed tensor | ||
*/ | ||
virtual void Compress(tensor_t grad, tensor_t& compressed) = 0; | ||
|
||
/*! | ||
* \brief Decompress function | ||
* | ||
* \param compressed compressed tensor | ||
* \param decompressed decompressed tensor | ||
*/ | ||
virtual void Decompress(tensor_t compressed, tensor_t& decompressed) = 0; | ||
|
||
/*! | ||
* \brief help function for error feedback `UpdateError` | ||
* | ||
* \param corrected gradient corrected with error | ||
* \param error error | ||
* \param compressed compressed gradient | ||
*/ | ||
virtual void FastUpdateError(tensor_t error, tensor_t corrected, | ||
tensor_t compressed) { | ||
BPS_LOG(FATAL) << "FastUpdateError is not implemented"; | ||
}; | ||
|
||
size_t size() const { return _size; } | ||
|
||
protected: | ||
/*! | ||
* \brief buffer | ||
*/ | ||
std::unique_ptr<byte_t[]> _buf; | ||
|
||
/*! | ||
* \brief original size | ||
*/ | ||
size_t _size; | ||
|
||
/*! | ||
* \brief CPU reducer | ||
*/ | ||
std::unique_ptr<CpuReducer> _cpu_reducer; | ||
}; | ||
|
||
} // namespace compressor | ||
} // namespace common | ||
} // namespace byteps | ||
|
||
#endif // BYTEPS_COMPRESSOR_COMPRESSOR_H |
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
Oops, something went wrong.