Skip to content

Commit 3b5e8d9

Browse files
committed
format
1 parent b0a0817 commit 3b5e8d9

File tree

16 files changed

+63
-66
lines changed

16 files changed

+63
-66
lines changed

delta/utils/misc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def log_vars(prefix, variables):
6565
''' logging TF varables metadata '''
6666
logging.info(f"{prefix}:")
6767
for var in variables:
68-
logging.info(f"\tname = {var.name}, shape = {var.shape}, device = {var.device}")
68+
logging.info(
69+
f"\tname = {var.name}, shape = {var.shape}, device = {var.device}")
6970

7071

7172
#pylint: disable=bad-continuation

delta/utils/solver/estimator_solver.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def get_assignment_map_from_checkpoint(self, tvars, init_checkpoint):
103103
def init_from_checkpoint(self):
104104
''' do transfer learning by init sub vars from other checkpoint. '''
105105
if 'transfer' not in self.config['solver']:
106-
return
106+
return
107107
transfer_cfg = self.config['solver']['transfer']
108108
enable = transfer_cfg['enable']
109109
if not enable:
@@ -118,6 +118,7 @@ def init_from_checkpoint(self):
118118
tvars = tf.trainable_variables()
119119
initialized_variable_names = {}
120120
if init_checkpoint:
121+
121122
def _filter_by_reg(tvars, include, exclude):
122123
include = include if include else []
123124
exclude = exclude if exclude else []
@@ -135,7 +136,8 @@ def _filter_by_reg(tvars, include, exclude):
135136
if m is None:
136137
outs.append(var)
137138
return outs
138-
tvars = _filter_by_reg(tvars, include, exclude)
139+
140+
tvars = _filter_by_reg(tvars, include, exclude)
139141
assignment_map, initialized_variable_names = \
140142
self.get_assignment_map_from_checkpoint(tvars, init_checkpoint)
141143
tf.train.init_from_checkpoint(init_checkpoint, assignment_map)
@@ -146,7 +148,7 @@ def _filter_by_reg(tvars, include, exclude):
146148
if var.name in initialized_variable_names:
147149
init_string = ", *INIT_FROM_CKPT*"
148150
logging.info(" name = %s, shape = %s%s", var.name, var.shape,
149-
init_string)
151+
init_string)
150152

151153
def model_fn(self):
152154
''' return model_fn '''

deltann/api/c_api.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
==============================================================================*/
1616

17+
#include <iostream>
1718
#include <string>
1819
#include <vector>
19-
#include <iostream>
2020

2121
#include "api/c_api.h"
2222
#include "core/config.h"
@@ -47,10 +47,10 @@ DeltaStatus DeltaSetInputs(InferHandel inf, Input* inputs, int num) {
4747
Runtime* rt = static_cast<Runtime*>(inf);
4848
std::vector<In> ins;
4949
for (int i = 0; i < num; ++i) {
50-
//std::cout << "set inputs name : " << inputs[i].input_name << "\n";
51-
//std::cout << "set inputs nelms: " << inputs[i].nelms << "\n";
50+
// std::cout << "set inputs name : " << inputs[i].input_name << "\n";
51+
// std::cout << "set inputs nelms: " << inputs[i].nelms << "\n";
5252

53-
const int *data = static_cast<const int*>(inputs[i].ptr);
53+
const int* data = static_cast<const int*>(inputs[i].ptr);
5454
if (inputs[i].shape == NULL) {
5555
ins.push_back(In(inputs[i].graph_name, inputs[i].input_name,
5656
inputs[i].ptr, inputs[i].nelms));

deltann/core/buffer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ class Buffer {
8585
void copy_from(const void* src, const std::size_t size) {
8686
DELTA_CHECK(_ptr);
8787
DELTA_CHECK(src);
88-
DELTA_CHECK(size <= _size)
89-
<< "expect size: " << size << " real size:" << _size;
88+
DELTA_CHECK(size <= _size) << "expect size: " << size
89+
<< " real size:" << _size;
9090
std::memcpy(_ptr, src, size);
9191
}
9292

9393
void copy_to(void* dst, const std::size_t size) {
9494
DELTA_CHECK(_ptr);
9595
DELTA_CHECK(dst);
96-
DELTA_CHECK(size <= _size)
97-
<< "expect size: " << size << " real size:" << _size;
96+
DELTA_CHECK(size <= _size) << "expect size: " << size
97+
<< " real size:" << _size;
9898
std::memcpy(dst, _ptr, size);
9999
}
100100

deltann/core/io.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class BaseInOutData {
185185
std::size_t bytes = nelms * delta_dtype_size(dtype);
186186
this->resize(bytes);
187187
_data->copy_from(src, bytes);
188-
}
188+
}
189189

190190
void copy_from(const float* src) { copy_from(src, this->nelms()); }
191191

@@ -203,7 +203,7 @@ class BaseInOutData {
203203

204204
#ifdef USE_TF
205205
tensorflow::TensorShape tensor_shape() const {
206-
//tensorflow::Status::Status status;
206+
// tensorflow::Status::Status status;
207207
const Shape& shape = this->shape();
208208
tensorflow::TensorShape ts;
209209
auto s = shape.vec();

deltann/core/runtime.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,8 @@ DeltaStatus Runtime::set_inputs(const std::vector<In>& ins) {
151151
<< in._shape;
152152
input.set_shape(in._shape);
153153
}
154-
DELTA_CHECK_EQ(in._nelms, input.nelms())
155-
<< in._nelms << ":"
156-
<< input.nelms();
154+
DELTA_CHECK_EQ(in._nelms, input.nelms()) << in._nelms << ":"
155+
<< input.nelms();
157156

158157
InputData input_data(input);
159158
input_data.copy_from(in._ptr, in._nelms);

deltann/core/runtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct In {
6161
std::string _graph_name;
6262
std::string _input_name;
6363
const void* _ptr;
64-
std::size_t _nelms; // elements
64+
std::size_t _nelms; // elements
6565
Shape _shape;
6666
};
6767

deltann/core/tfmodel.cc

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,28 @@ TFModel::TFModel(ModelMeta model_meta, int num_threads)
7474
void TFModel::feed_tensor(Tensor* tensor, const InputData& input) {
7575
std::int64_t num_elements = tensor->NumElements();
7676
switch (input.dtype()) {
77-
case DataType::DELTA_FLOAT32:{
78-
std::cout << "input: " << num_elements << " " << tensor->TotalBytes() << std::endl;
77+
case DataType::DELTA_FLOAT32: {
78+
std::cout << "input: " << num_elements << " " << tensor->TotalBytes()
79+
<< std::endl;
7980
auto ptr = tensor->flat<float>().data();
8081
std::fill_n(ptr, num_elements, 0.0);
81-
std::copy_n(static_cast<float*>(input.ptr()), num_elements,
82-
ptr);
82+
std::copy_n(static_cast<float*>(input.ptr()), num_elements, ptr);
8383
break;
8484
}
85-
case DataType::DELTA_INT32:{
85+
case DataType::DELTA_INT32: {
8686
std::copy_n(static_cast<int*>(input.ptr()), num_elements,
8787
tensor->flat<int>().data());
8888
break;
89-
}
89+
}
9090
case DataType::DELTA_CHAR: {
9191
char* cstr = static_cast<char*>(input.ptr());
9292
std::string str = std::string(cstr);
9393
tensor->scalar<tensorflow::tstring>()() = str;
9494
break;
9595
}
96-
default:{
96+
default: {
9797
LOG_FATAL << "Not support dtype:" << delta_dtype_str(input.dtype());
98-
}
98+
}
9999
}
100100
}
101101

@@ -107,7 +107,7 @@ void TFModel::fetch_tensor(const Tensor& tensor, OutputData* output) {
107107
// copy data
108108
std::size_t num_elements = tensor.NumElements();
109109
std::size_t total_bytes = tensor.TotalBytes();
110-
std::cout << "output: " << num_elements << " " << total_bytes << "\n";
110+
std::cout << "output: " << num_elements << " " << total_bytes << "\n";
111111
DELTA_CHECK(num_elements == output->nelms())
112112
<< "expect " << num_elements << "elems, but given " << output->nelms();
113113

@@ -186,33 +186,32 @@ int TFModel::run(const std::vector<InputData>& inputs,
186186
set_feeds(&feeds, inputs);
187187
set_fetches(&fetches, *output);
188188

189-
//std::cout << "input xxxxxxxxxxxxxxxxx"<< "\n";
190-
//auto ti = feeds[0].second;
191-
//for (auto i = 0; i < ti.NumElements(); i++){
189+
// std::cout << "input xxxxxxxxxxxxxxxxx"<< "\n";
190+
// auto ti = feeds[0].second;
191+
// for (auto i = 0; i < ti.NumElements(); i++){
192192
// std::cout << std::showpoint << ti.flat<float>()(i) << " ";
193193
// if (i % 40 == 1){std::cout << "\n";}
194194
//}
195-
//std::cout << "\n";
196-
//std::cout << "input -------------------"<< "\n";
197-
195+
// std::cout << "\n";
196+
// std::cout << "input -------------------"<< "\n";
198197

199198
// Session run
200199
RunOptions run_options;
201200
RunMetadata run_meta;
202-
tensorflow::Status s = _bundle.GetSession()->Run(run_options, feeds, fetches, {},
203-
&output_tensors, &run_meta);
201+
tensorflow::Status s = _bundle.GetSession()->Run(
202+
run_options, feeds, fetches, {}, &output_tensors, &run_meta);
204203
if (!s.ok()) {
205204
LOG_FATAL << "Error, TF Model run failed: " << s;
206205
exit(-1);
207206
}
208207

209-
//std::cout << "output xxxxxxxxxxxxxxxxx"<< "\n";
210-
//auto t = output_tensors[0];
211-
//for (auto i = 0; i < t.NumElements(); i++){
208+
// std::cout << "output xxxxxxxxxxxxxxxxx"<< "\n";
209+
// auto t = output_tensors[0];
210+
// for (auto i = 0; i < t.NumElements(); i++){
212211
// std::cout << std::showpoint << t.flat<float>()(i) << " ";
213212
//}
214-
//std::cout << "\n";
215-
//std::cout << "output -------------------"<< "\n";
213+
// std::cout << "\n";
214+
// std::cout << "output -------------------"<< "\n";
216215

217216
get_featches(output_tensors, output);
218217

@@ -287,13 +286,14 @@ DeltaStatus TFModel::load_from_saved_model() {
287286
LOG_INFO << "load saved model from path: " << path;
288287
if (!MaybeSavedModelDirectory(path)) {
289288
LOG_FATAL << "SaveModel not in :" << path;
290-
return DeltaStatus::STATUS_ERROR;
289+
return DeltaStatus::STATUS_ERROR;
291290
}
292291

293-
tensorflow::Status s = LoadSavedModel(options, run_options, path,
294-
{tensorflow::kSavedModelTagServe}, &_bundle);
292+
tensorflow::Status s = LoadSavedModel(
293+
options, run_options, path, {tensorflow::kSavedModelTagServe}, &_bundle);
295294
if (!s.ok()) {
296-
LOG_FATAL << "Failed Load model from saved_model.pb : " << s.error_message();
295+
LOG_FATAL << "Failed Load model from saved_model.pb : "
296+
<< s.error_message();
297297
}
298298

299299
return DeltaStatus::STATUS_OK;

deltann/examples/speaker/test.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ struct DeltaModel {
7474
}
7575

7676
DeltaStatus SetInputs(T* buf, const std::vector<int> shape) {
77-
return this->SetInputs(buf, this->NumElems(shape), shape.data(), shape.size());
77+
return this->SetInputs(buf, this->NumElems(shape), shape.data(),
78+
shape.size());
7879
}
7980

8081
DeltaStatus SetInputs(T* buf, int nelms, const int* shape, const int ndims) {

deltann/infer/delta_infer/core/scatter_search.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ struct Compare {
1111
Compare() {
1212
std::vector<absl::flat_hash_set<std::string>> op_maps = {
1313
{
14-
"BatchMatMulV2",
15-
"BatchMatMul",
14+
"BatchMatMulV2", "BatchMatMul",
1615
},
1716
{"Const", "Shape"},
1817
};

0 commit comments

Comments
 (0)