mil-tokyo / webdnn

The Fastest DNN Running Framework on Web Browser
https://mil-tokyo.github.io/webdnn
Other
1.97k stars 146 forks source link

Failed creating fallback and webgl descriptors #780

Open Nithanaroy opened 6 years ago

Nithanaroy commented 6 years ago

For a LSTM network created in Keras, I was able to convert keras model to webassembly and webgpu backends using bin/convert_keras.py

When I try to convert the same model to either fallback or webgl backends, it fails with this stacktrace:

emojify $ python3 ../webdnn/bin/convert_keras.py emojify-model.h5 --input_shape '(1,10)' --out output_keras --backend webgl,fallback
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
  return f(*args, **kwds)
[convert_keras.py] Generating feedforward graph
2018-02-20 19:02:29.254084: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/util/console.py:30: Warning: [KerasConverter] omitting dropout
  warnings.warn(message, category)
[convert_keras.py] Generating graph descriptor
[convert_keras.py] BackendName: webgl
[convert_keras.py] Failed generating descriptor for webgl backend
Traceback (most recent call last):
  File "../webdnn/bin/convert_keras.py", line 97, in main
    graph_exec_data = generate_descriptor(backend, graph, constant_encoder_name=args.encoding)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/interface/generator.py", line 107, in generate_descriptor
    return generator(graph, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/webgl/generator.py", line 92, in generate
    return WebGLDescriptorGenerator.generate(graph, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/webgl/generator.py", line 45, in generate
    graph, _ = WebGLOptimizeRule().optimize(copy.deepcopy(original_graph))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/graph/optimize_rule.py", line 110, in optimize
    graph, flag_changed = sub_rule.optimize(graph)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/graph/optimize_rule.py", line 110, in optimize
    graph, flag_changed = sub_rule.optimize(graph)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/graph/optimize_rule.py", line 110, in optimize
    graph, flag_changed = sub_rule.optimize(graph)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/webgl/optimize_rules/split_texture/split_variable.py", line 42, in optimize
    _split_axis(v, axis, graph)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/webgl/optimize_rules/split_texture/split_variable.py", line 89, in _split_axis
    _split_tensorwise(graph, op, v, [v1, v2], axis)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/webgl/optimize_rules/split_texture/split_variable.py", line 911, in _split_tensorwise
    x_0, x_1 = SplitAxis(None, axis=axis, sections=[s1])(x)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/graph/operators/split_axis.py", line 45, in __call__
    assert i_from < i_to, f"[SplitAxis] sections must be sorted ascending order: sections={sections}, sections[{i}]={i_from}, " \
AssertionError: [SplitAxis] sections must be sorted ascending order: sections=[0, 25, 1], sections[1]=25, sections[2]=1

[convert_keras.py] BackendName: fallback
[convert_keras.py] Failed generating descriptor for fallback backend
Traceback (most recent call last):
  File "../webdnn/bin/convert_keras.py", line 97, in main
    graph_exec_data = generate_descriptor(backend, graph, constant_encoder_name=args.encoding)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/interface/generator.py", line 107, in generate_descriptor
    return generator(graph, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/fallback/generator.py", line 75, in generate
    return FallbackDescriptorGenerator.generate(graph, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/fallback/generator.py", line 64, in generate
    kernels=cls.generate_kernels(graph, memory_layout),
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/interface/generator.py", line 57, in generate_kernels
    raise NotImplementedError(f"[{cls.__name__}] Operator {op} is not handled by any generator handler")
NotImplementedError: [FallbackDescriptorGenerator] Operator <Embedding inputs={'x': <Variable Variable2 shape=(1, 10), order=[N, T]>, 'w': <ConstantVariable ConstantVariable0 shape=(400001, 50), order=[C, N]>}, outputs={'y': <Variable Variable3 shape=(1, 10, 50), order=[N, T, C]>}> is not handled by any generator handler
Nithanaroy commented 6 years ago

In fact the given lstm in source code also doesn't compile webgl and fallback descriptors. The error in the case of webgl looks the same as mine.

lstm (master)*$ python3.6 imdb_lstm.py
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
  return f(*args, **kwds)
Use already trained model
Converting model into WebDNN format (graph descriptor)
$ python3.6 ../../bin/convert_keras.py output_keras/imdb_lstm.h5 --input_shape '(1,80)' --out output_keras --backend webgl,fallback
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/_bootstrap.py:219: RuntimeWarning: compiletime version 3.5 of module 'tensorflow.python.framework.fast_tensor_util' does not match runtime version 3.6
  return f(*args, **kwds)
[convert_keras.py] Generating feedforward graph
2018-02-20 23:40:27.357091: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
[convert_keras.py] Generating graph descriptor
[convert_keras.py] BackendName: webgl
[convert_keras.py] Failed generating descriptor for webgl backend
Traceback (most recent call last):
  File "../../bin/convert_keras.py", line 97, in main
    graph_exec_data = generate_descriptor(backend, graph, constant_encoder_name=args.encoding)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/interface/generator.py", line 107, in generate_descriptor
    return generator(graph, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/webgl/generator.py", line 92, in generate
    return WebGLDescriptorGenerator.generate(graph, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/webgl/generator.py", line 61, in generate
    kernels = cls.generate_kernels(graph)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/webgl/generator.py", line 84, in generate_kernels
    raise NotImplementedError(f"[{cls.__name__}] Operator {op} is not handled by any generator handler")
NotImplementedError: [WebGLDescriptorGenerator] Operator <Embedding inputs={'x': <Variable Variable2 shape=(1, 80), order=[N, T]>, 'w': <ConstantVariable ConstantVariable0 shape=(20000, 128), order=[C, N]>}, outputs={'y': <Variable Variable3 shape=(1, 80, 128), order=[N, T, C]>}> is not handled by any generator handler

[convert_keras.py] BackendName: fallback
[convert_keras.py] Failed generating descriptor for fallback backend
Traceback (most recent call last):
  File "../../bin/convert_keras.py", line 97, in main
    graph_exec_data = generate_descriptor(backend, graph, constant_encoder_name=args.encoding)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/interface/generator.py", line 107, in generate_descriptor
    return generator(graph, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/fallback/generator.py", line 75, in generate
    return FallbackDescriptorGenerator.generate(graph, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/fallback/generator.py", line 64, in generate
    kernels=cls.generate_kernels(graph, memory_layout),
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/webdnn/backend/interface/generator.py", line 57, in generate_kernels
    raise NotImplementedError(f"[{cls.__name__}] Operator {op} is not handled by any generator handler")
NotImplementedError: [FallbackDescriptorGenerator] Operator <Embedding inputs={'x': <Variable Variable2 shape=(1, 80), order=[N, T]>, 'w': <ConstantVariable ConstantVariable0 shape=(20000, 128), order=[C, N]>}, outputs={'y': <Variable Variable3 shape=(1, 80, 128), order=[N, T, C]>}> is not handled by any generator handler

Traceback (most recent call last):
  File "imdb_lstm.py", line 130, in <module>
    main()
  File "imdb_lstm.py", line 124, in main
    subprocess.check_call(convert_keras_command, shell=True)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'python3.6 ../../bin/convert_keras.py output_keras/imdb_lstm.h5 --input_shape '(1,80)' --out output_keras --backend webgl,fallback' returned non-zero exit status 1.