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

Make var of STRINGS dtype able to get lod_level property #39077

Merged
merged 1 commit into from
Jan 24, 2022
Merged
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
6 changes: 5 additions & 1 deletion python/paddle/fluid/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,10 @@ def lod_level(self):
Examples:
.. code-block:: python

import paddle
import paddle.fluid as fluid

paddle.enable_static()
cur_program = fluid.Program()
cur_block = cur_program.current_block()
new_variable = cur_block.create_var(name="X",
Expand All @@ -1773,7 +1776,8 @@ def lod_level(self):
"""
if self.type == core.VarDesc.VarType.SELECTED_ROWS:
raise Exception("SelectedRows DO NOT supprt lod")

if self.type == core.VarDesc.VarType.STRINGS:
return None
return self.desc.lod_level()

@property
Expand Down
6 changes: 6 additions & 0 deletions python/paddle/fluid/tests/unittests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def test_var(self):
self.assertRaises(ValueError,
lambda: b.create_var(name="fc.w", shape=(24, 100)))

w = b.create_var(
dtype=paddle.fluid.core.VarDesc.VarType.STRINGS,
shape=[1],
name="str_var")
self.assertEqual(None, w.lod_level)

def test_element_size(self):
with fluid.program_guard(Program(), Program()):
x = paddle.static.data(name='x1', shape=[2], dtype='bool')
Expand Down