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

DebertaV3MaskedLM example don't work #1622

Open
mrektor opened this issue May 7, 2024 · 2 comments
Open

DebertaV3MaskedLM example don't work #1622

mrektor opened this issue May 7, 2024 · 2 comments
Assignees
Labels
type:Bug Something isn't working

Comments

@mrektor
Copy link

mrektor commented May 7, 2024

Describe the bug

The example from the (documentation)[https://keras.io/api/keras_nlp/models/deberta_v3/deberta_v3_masked_lm/] does not work

To Reproduce

import os

os.environ["KERAS_BACKEND"] = "tensorflow"  # or "tensorflow" or "torch" or "jax"

import keras_nlp
import keras

# Use mixed precision to speed up all training in this guide.
keras.mixed_precision.set_global_policy("mixed_float16")

BATCH_SIZE = 16


features = ["The quick brown fox jumped.", "I forgot my homework."]

masked_lm = keras_nlp.models.DebertaV3MaskedLM.from_preset(
    "deberta_v3_base_en",
)
masked_lm.fit(x=features, batch_size=2)

Expected behavior
The training loop should start

Additional context
Throws instead this nasty error:

Traceback (most recent call last):
  File "/home/ettore.mariotti/deberta_gal/deberta_keras.py", line 19, in <module>
    masked_lm.fit(x=features, batch_size=2)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/keras_nlp/src/utils/pipeline_model.py", line 181, in fit
    x = x.map(
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 2299, in map
    return map_op._map_v2(
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/data/ops/map_op.py", line 40, in _map_v2
    return _ParallelMapDataset(
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/data/ops/map_op.py", line 148, in __init__
    self._map_func = structured_function.StructuredFunctionWrapper(
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/data/ops/structured_function.py", line 265, in __init__
    self._function = fn_factory()
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 1251, in get_concrete_function
    concrete = self._get_concrete_function_garbage_collected(*args, **kwargs)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 1221, in _get_concrete_function_garbage_collected
    self._initialize(args, kwargs, add_initializers_to=initializers)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 696, in _initialize
    self._concrete_variable_creation_fn = tracing_compilation.trace_function(
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compilation.py", line 178, in trace_function
    concrete_function = _maybe_define_function(
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compilation.py", line 283, in _maybe_define_function
    concrete_function = _create_concrete_function(
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/tracing_compilation.py", line 310, in _create_concrete_function
    traced_func_graph = func_graph_module.func_graph_from_py_func(
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/framework/func_graph.py", line 1059, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py", line 599, in wrapped_fn
    out = weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/data/ops/structured_function.py", line 231, in wrapped_fn
    ret = wrapper_helper(*args)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/data/ops/structured_function.py", line 161, in wrapper_helper
    ret = autograph.tf_convert(self._func, ag_ctx)(*nested_args)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 693, in wrapper
    raise e.ag_error_metadata.to_exception(e)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 690, in wrapper
    return converted_call(f, args, kwargs, options=options)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 439, in converted_call
    result = converted_f(*effective_args, **kwargs)
  File "/tmp/__autograph_generated_file80f1z6yd.py", line 36, in tf__preprocess_samples
    ag__.if_stmt(ag__.ld(self).preprocessor is not None, if_body, else_body, get_state, set_state, ('do_return', 'retval_'), 2)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/autograph/operators/control_flow.py", line 1217, in if_stmt
    _py_if_stmt(cond, body, orelse)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/autograph/operators/control_flow.py", line 1270, in _py_if_stmt
    return body() if cond else orelse()
  File "/tmp/__autograph_generated_file80f1z6yd.py", line 23, in if_body
    retval_ = ag__.converted_call(ag__.ld(self).preprocessor, (ag__.ld(x),), dict(y=ag__.ld(y), sample_weight=ag__.ld(sample_weight)), fscope)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 439, in converted_call
    result = converted_f(*effective_args, **kwargs)
  File "/tmp/__autograph_generated_fileyo02hq6s.py", line 12, in tf____call__
    outputs = ag__.converted_call(ag__.converted_call(ag__.ld(super), (), None, fscope).__call__, tuple(ag__.ld(args)), dict(**ag__.ld(kwargs)), fscope)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 377, in converted_call
    return _call_unconverted(f, args, kwargs, options)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 459, in _call_unconverted
    return f(*args, **kwargs)
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/keras/src/utils/traceback_utils.py", line 122, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/keras_nlp/src/models/deberta_v3/deberta_v3_masked_lm_preprocessor.py", line 151, in build
    vocabulary_size=self.tokenizer.vocabulary_size(),
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/keras_nlp/src/models/deberta_v3/deberta_v3_tokenizer.py", line 135, in vocabulary_size
    sentence_piece_size = super().vocabulary_size()
  File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/keras_nlp/src/tokenizers/sentence_piece_tokenizer.py", line 185, in vocabulary_size
    return int(self._sentence_piece.vocab_size().numpy())
AttributeError: in user code:

    File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/keras_nlp/src/models/task.py", line 98, in preprocess_samples  *
        return self.preprocessor(x, y=y, sample_weight=sample_weight)
    File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/keras_nlp/src/layers/preprocessing/preprocessing_layer.py", line 49, in __call__  *
        outputs = super().__call__(*args, **kwargs)
    File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/keras/src/utils/traceback_utils.py", line 122, in error_handler  **
        raise e.with_traceback(filtered_tb) from None
    File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/keras_nlp/src/models/deberta_v3/deberta_v3_masked_lm_preprocessor.py", line 151, in build
        vocabulary_size=self.tokenizer.vocabulary_size(),
    File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/keras_nlp/src/models/deberta_v3/deberta_v3_tokenizer.py", line 135, in vocabulary_size
        sentence_piece_size = super().vocabulary_size()
    File "/home/ettore.mariotti/deepenv/lib64/python3.9/site-packages/keras_nlp/src/tokenizers/sentence_piece_tokenizer.py", line 185, in vocabulary_size
        return int(self._sentence_piece.vocab_size().numpy())

    AttributeError: 'SymbolicTensor' object has no attribute 'numpy'

Would you like to help us fix it?
Yes please

@SuryanarayanaY SuryanarayanaY added the type:Bug Something isn't working label May 16, 2024
@SuryanarayanaY
Copy link

Hi @mrektor ,

I have replicated the reported issue and attached gist here.

@mrektor
Copy link
Author

mrektor commented Jun 20, 2024

So I guess this has not been fixed yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants