agemagician / CodeTrans

Pretrained Language Models for Source code
MIT License
247 stars 32 forks source link

Error in model.predict - TypeError: 'str' object is not callable #3

Closed yazdipour closed 3 years ago

yazdipour commented 3 years ago

Hi.

I was trying to run your code in single task/api generation/t5 interface/base_model.ipynb on COLAB and I am receiving this error after model.predict.

model.predict(
    input_file="input.txt",
    output_file=predict_outputs_path,
    checkpoint_steps=840000,
    beam_size=4,
    vocabulary=vocab, 
    # Select the most probable output token at each step.
    temperature=0,
)
=======================================
INFO:tensorflow:Using config: {'_model_dir': 'base', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': 5000, '_save_checkpoints_secs': None, '_session_config': allow_soft_placement: true
graph_options {
  rewrite_options {
    meta_optimizer_iterations: ONE
  }
}
, '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': None, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_experimental_max_worker_delay_secs': None, '_session_creation_timeout_secs': 7200, '_checkpoint_save_graph_def': True, '_service': None, '_cluster_spec': ClusterSpec({}), '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1, '_tpu_config': TPUConfig(iterations_per_loop=100, num_shards=None, num_cores_per_replica=1, per_host_input_for_training=4, tpu_job_name=None, initial_infeed_sleep_secs=None, input_partition_dims=None, eval_training_input_configuration=2, experimental_host_call_every_n_steps=1, experimental_allow_per_host_v2_parallel_get_next=False, experimental_feed_hook=None), '_cluster': None}
INFO:tensorflow:_TPUContext: eval_on_tpu True
WARNING:tensorflow:eval_on_tpu ignored because use_tpu is False.
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-e1bf683e0ef5> in <module>()
      7     vocabulary=vocab,
      8     # Select the most probable output token at each step.
----> 9     temperature=0,
     10 )

4 frames
/usr/local/lib/python3.7/dist-packages/mesh_tensorflow/transformer/utils.py in infer_model(estimator, vocabulary, sequence_length, batch_size, model_type, model_dir, eval_checkpoint_step, checkpoint_paths, decode_fn)
   1853         batch_size=batch_size,
   1854         sequence_length=sequence_length,
-> 1855         checkpoint_path=checkpoint_path)
   1856 
   1857 

TypeError: 'str' object is not callable
  In call to configurable 'infer_model' (<function infer_model at 0x7f68488db950>)

How can I fix this issue?

agemagician commented 3 years ago

Hi yazdipour,

Unfortunately, the T5 library is keeping changing its code and causes issues with the updated Colab environment. Hence, we dropped the support of T5 library and switched to Hugging-Face library which is more stable.

T5 Colab examples will be dropped from the next releases.

You can achieve the same results using the hugging-face library: https://github.com/agemagician/CodeTrans/blob/main/prediction/single%20task/api%20generation/base_model.ipynb https://github.com/agemagician/CodeTrans/blob/main/prediction/single%20task/api%20generation/small_model.ipynb