Bert-as-service: Unsuccessful TensorSliceReader Constructor with pretrained BERT

Created on 31 Jul 2019  路  4Comments  路  Source: hanxiao/bert-as-service

Prerequisites

System information

  • OS Platform: Windows 10
  • TensorFlow installed from (source or binary): binary
  • TensorFlow version: 1.14.0
  • Python version: 3.6.8
  • bert-as-service version: newest
  • GPU model and memory: GTX 1080 Ti

    - CPU model and memory: Intel(R) Core(TM) i7-7700 CPU @ 3.60GH

Description

I'm using this command to start the server:

bert-serving-start -model_dir bert-cased-german/

Then this issue shows up:
```usage: /root/bert_venv/bin/bert-serving-start -model_dir bert-cased-german/
ARG VALUE


       ckpt_name = bert_model.ckpt
     config_name = bert_config.json
            cors = *
             cpu = False
      device_map = []
   do_lower_case = True

fixed_embed_length = False
fp16 = False
gpu_memory_fraction = 0.5
graph_tmp_dir = None
http_max_connect = 10
http_port = None
mask_cls_sep = False
max_batch_size = 256
max_seq_len = 25
model_dir = bert-cased-german/
num_worker = 1
pooling_layer = [-2]
pooling_strategy = REDUCE_MEAN
port = 5555
port_out = 5556
prefetch_size = 10
priority_batch_size = 16
show_tokens_to_client = False
tuned_model_dir = None
verbose = False
xla = False

I:VENTILATOR:[__i:__i: 67]:freeze, optimize and export graph, could take a while...
WARNING: Logging before flag parsing goes to stderr.
I0731 08:09:07.672543 140386794571584 __init__.py:67] freeze, optimize and export graph, could take a while...
W0731 08:09:07.679953 140386794571584 deprecation_wrapper.py:119] From /root/bert_venv/lib/python3.6/site-packages/bert_serving/server/helper.py:180: The name tf.logging.set_verbosity is deprecated. Please use tf.compat.v1.logging.set_verbosity instead.

W0731 08:09:07.680354 140386794571584 deprecation_wrapper.py:119] From /root/bert_venv/lib/python3.6/site-packages/bert_serving/server/helper.py:180: The name tf.logging.ERROR is deprecated. Please use tf.compat.v1.logging.ERROR instead.

I:GRAPHOPT:[gra:opt: 52]:model config: bert-cased-german/bert_config.json
I0731 08:09:07.682091 140386794571584 graph.py:52] model config: bert-cased-german/bert_config.json
I:GRAPHOPT:[gra:opt: 55]:checkpoint: bert-cased-german/bert_model.ckpt
I0731 08:09:07.682227 140386794571584 graph.py:55] checkpoint: bert-cased-german/bert_model.ckpt
I:GRAPHOPT:[gra:opt: 59]:build graph...
I0731 08:09:07.683006 140386794571584 graph.py:59] build graph...
E:GRAPHOPT:[gra:opt:150]:fail to optimize the graph!
Traceback (most recent call last):
File "/root/bert_venv/lib/python3.6/site-packages/bert_serving/server/graph.py", line 81, in optimize_graph
) = modeling.get_assignment_map_from_checkpoint(tvars, init_checkpoint)
File "/root/bert_venv/lib/python3.6/site-packages/bert_serving/server/bert/modeling.py", line 331, in get_assignment_map_from_checkpoint
init_vars = tf.train.list_variables(init_checkpoint)
File "/root/bert_venv/lib/python3.6/site-packages/tensorflow/python/training/checkpoint_utils.py", line 97, in list_variables
reader = load_checkpoint(ckpt_dir_or_file)
File "/root/bert_venv/lib/python3.6/site-packages/tensorflow/python/training/checkpoint_utils.py", line 66, in load_checkpoint
return pywrap_tensorflow.NewCheckpointReader(filename)
File "/root/bert_venv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 636, in NewCheckpointReader
return CheckpointReader(compat.as_bytes(filepattern))
File "/root/bert_venv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 648, in __init__
this = _pywrap_tensorflow_internal.new_CheckpointReader(filename)
tensorflow.python.framework.errors_impl.NotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for bert-cased-german/bert_model.ckpt
E0731 08:09:11.066254 140386794571584 graph.py:150] fail to optimize the graph!
Traceback (most recent call last):
File "/root/bert_venv/lib/python3.6/site-packages/bert_serving/server/graph.py", line 81, in optimize_graph
) = modeling.get_assignment_map_from_checkpoint(tvars, init_checkpoint)
File "/root/bert_venv/lib/python3.6/site-packages/bert_serving/server/bert/modeling.py", line 331, in get_assignment_map_from_checkpoint
init_vars = tf.train.list_variables(init_checkpoint)
File "/root/bert_venv/lib/python3.6/site-packages/tensorflow/python/training/checkpoint_utils.py", line 97, in list_variables
reader = load_checkpoint(ckpt_dir_or_file)
File "/root/bert_venv/lib/python3.6/site-packages/tensorflow/python/training/checkpoint_utils.py", line 66, in load_checkpoint
return pywrap_tensorflow.NewCheckpointReader(filename)
File "/root/bert_venv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 636, in NewCheckpointReader
return CheckpointReader(compat.as_bytes(filepattern))
File "/root/bert_venv/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py", line 648, in __init__
this = _pywrap_tensorflow_internal.new_CheckpointReader(filename)
tensorflow.python.framework.errors_impl.NotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for bert-cased-german/bert_model.ckpt
Traceback (most recent call last):
File "/root/bert_venv/bin/bert-serving-start", line 10, in
sys.exit(main())
File "/root/bert_venv/lib/python3.6/site-packages/bert_serving/server/cli/__init__.py", line 4, in main
with BertServer(get_run_args()) as server:
File "/root/bert_venv/lib/python3.6/site-packages/bert_serving/server/__init__.py", line 71, in __init__
self.graph_path, self.bert_config = pool.apply(optimize_graph, (self.args,))
TypeError: 'NoneType' object is not iterable
```

The content of the model dir:

bert-base-german-cased.index
bert-base-german-cased.meta
bert-base-german.data-00000-of-00001
bert_config.json
vocab.txt

I followed the Chinese Law Tutorial on the same machine and it works perfectly. Since I want to evaluate document classification especially for german, I want to serve the features for this pretrained BERT - tensorflow-version.

...

Most helpful comment

@qiunian711

First, rename:
bert-base-german.data-00000-of-00001 to
bert-base-german-cased.data-00000-of-00001
so that you have index, meta and data files with the same name. The content of the folder should look like this:

bert-base-german-cased.index
bert-base-german-cased.meta
bert-base-german-cased.data-00000-of-00001
bert_config.json
vocab.txt

Now, you need to pass an additional parameter to bert-serving-start:

bert-serving-start -model_dir <folder-name> -ckpt_name bert-base-german-cased

This is because Bert expects ckpt_name = bert_model.ckpt by default, as shown in the log under
ARG VALUE table.

Another option would be to rename index, meta and data files to bert_model.ckpt.index, etc.

All 4 comments

@JulianGerhard21
hello! have you fixed this bug?
I have the same proflem

@qiunian711

First, rename:
bert-base-german.data-00000-of-00001 to
bert-base-german-cased.data-00000-of-00001
so that you have index, meta and data files with the same name. The content of the folder should look like this:

bert-base-german-cased.index
bert-base-german-cased.meta
bert-base-german-cased.data-00000-of-00001
bert_config.json
vocab.txt

Now, you need to pass an additional parameter to bert-serving-start:

bert-serving-start -model_dir <folder-name> -ckpt_name bert-base-german-cased

This is because Bert expects ckpt_name = bert_model.ckpt by default, as shown in the log under
ARG VALUE table.

Another option would be to rename index, meta and data files to bert_model.ckpt.index, etc.

@qiunian711

First, rename:
bert-base-german.data-00000-of-00001 to
bert-base-german-cased.data-00000-of-00001
so that you have index, meta and data files with the same name. The content of the folder should look like this:

bert-base-german-cased.index
bert-base-german-cased.meta
bert-base-german-cased.data-00000-of-00001
bert_config.json
vocab.txt

Now, you need to pass an additional parameter to bert-serving-start:

bert-serving-start -model_dir <folder-name> -ckpt_name bert-base-german-cased

This is because Bert expects ckpt_name = bert_model.ckpt by default, as shown in the log under
ARG VALUE table.

Another option would be to rename index, meta and data files to bert_model.ckpt.index, etc.

It worked, but in my case, you have to rename 3 files index, meta and data to bert_model. If you add an additional param like -ckpt_name bert-base-german-cased, it will assume that you have a subfolder inside the pretrained model named bert-base-german-cased.

Thanks anyway

hello! have you fixed this bug?
I have the same proflem

Was this page helpful?
0 / 5 - 0 ratings