Closed ZiggerZZ closed 1 year ago
It would be great with an update to Tensorflow 2.0 (or later) - It has been on my wishlist for a long time :-)
Sample is changed to a class, so we can inject the different parameters for thresholds etc.
Looking at your commits sample is very different as your version loads the configuration, but latest gets it injected.
Primary reason for injecting it is it will allow us to have different version of the configuration for each bot.
So my best advise would be to get latest and then reapply your changes, but perhaps Lorand has better ideas.
Worst case I will look at your changes and do the work.
My intention was to update sample.py
to the latest version without any of my changes, isn't it the case now?
I would be happy to make changes but unfortunately I'm unable to run gameserver.py
even on the main branch.
Clone the latest version in a new directory, and create an issue if gameserver.py can't run, or any other error you might see.
I have made some structural changes with directories regarding config files, and might have missed soemthing
I'm unable to run Python 3.7 with TF 1.15 on my Mac, that's why I had to upgrade the code to TF 2.0 :)
Here's the error I'm getting:
(ben) zz@zz-MacBook-Pro src % python gameserver.py
Playing random deals or deals from the client
Reading configuration from ./config/default.conf
2023-08-26 22:27:25.171824: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:375] MLIR V1 optimization pass is not enabled
Traceback (most recent call last):
File "/Users/zz/PycharmProjects/ben/src/gameserver.py", line 69, in <module>
models = Models.from_conf(conf.load(configfile))
File "/Users/zz/PycharmProjects/ben/src/nn/models.py", line 26, in from_conf
bidder_model=Bidder('bidder', os.path.join(
File "/Users/zz/PycharmProjects/ben/src/nn/bidder.py", line 17, in __init__
self.output_softmax = tf.nn.softmax(self.graph.get_tensor_by_name('out_bid_logit:0'))
File "/Users/zz/mambaforge/envs/ben/lib/python3.9/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/Users/zz/mambaforge/envs/ben/lib/python3.9/site-packages/tensorflow/python/eager/execute.py", line 53, in quick_execute
tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
TypeError: <tf.Tensor 'out_bid_logit:0' shape=(None, 40) dtype=float32> is out of scope and cannot be used here. Use return values, explicit Python locals or TensorFlow collections to access it.
Please see https://www.tensorflow.org/guide/function#all_outputs_of_a_tffunction_must_be_return_values for more information.
<tf.Tensor 'out_bid_logit:0' shape=(None, 40) dtype=float32> was defined here:
<unknown>
The tensor <tf.Tensor 'out_bid_logit:0' shape=(None, 40) dtype=float32> cannot be accessed from here, because it was defined in PyGraph<5628544912>, which is out of scope.
Looking at the traceback there is a reference to Python 3.9 and as long we are on Tensorflow 1.15 we must stay at Python 3.7. Could that be the problem?
I have installed virtualenv instead of anaconda, and that is working OK with Python 3.7 - but I am on windows.
If we upgrade to TF 2.0 can we still use the trained models?
Around 3 weeks ago my patched version with TF 2.0 and Python 3.9 was working. If you haven't made changes to the model, I suppose it should be working.
Looks like simple changes as you are keeping V1 functionality.
But there is no Tensorflow 2.0 available for Python 3.9. When I tried to install it it looked like 2.5 was the lowest version. Am I missing something?
Ok, I installed TF 2.5 and got the same error as you have, so I assume you was trying Python 3.9 and TF2.5 as Python 3.7 is End of life
Add
tf.compat.v1.disable_eager_execution()
and you should be able to use latest version
For some reason I didn't get the same error when launching gameserver on my branch again. Maybe I was on a wrong branch. My conda_setup.sh
contains conda create -n ben python=3.9
and pip install tensorflow==2.0
but I think we can even use latest tensorflow or >=2.0.
I pushed a commit fixing a few numpy issues, specifically
File "/Users/zz/PycharmProjects/ben/src/sample.py", line 337, in shuffle_cards_bidding_info
ak_out_i = np.vectorize(np.random.permutation,
File "/Users/zz/mambaforge/envs/ben/lib/python3.9/site-packages/numpy/lib/function_base.py", line 2329, in __call__
return self._vectorize_call(func=func, args=vargs)
File "/Users/zz/mambaforge/envs/ben/lib/python3.9/site-packages/numpy/lib/function_base.py", line 2403, in _vectorize_call
res = self._vectorize_call_with_signature(func, args)
File "/Users/zz/mambaforge/envs/ben/lib/python3.9/site-packages/numpy/lib/function_base.py", line 2443, in _vectorize_call_with_signature
results = func(*(arg[index] for arg in args))
File "mtrand.pyx", line 4712, in numpy.random.mtrand.RandomState.permutation
File "mtrand.pyx", line 4577, in numpy.random.mtrand.RandomState.shuffle
and
AttributeError: module 'numpy' has no attribute 'int'.
`np.int` was a deprecated alias for the builtin `int`.
I played a few games as a defender or a declarer and all went smoothly!
Relaxed tf requirements. Also, there is still conda install tensorflow-estimator=1.15
in conda_setup.sh
, we might need to update it. What do you use tensorflow-estimator
for?
I have manually merged the changes for TF 2.X into my repository and all seems to be working fine. Will du some more testing
I had some trouble with the training and to get it to run I had to ad tensorflow-estimator in a specific version. I will try removing it.
What do you think about trying BEN without conda and on latest Python version - would that cause trouble on Mac?
If we should use virtual environments anaconda is a bit annoying on windows, so virtual env would probably be better
I have just tested game.py on Python 3.11 and TF 2.13 and it seems to work. Only trouble I had was that I had to use admin rights to install Tensorflow.
I am no Github expert. I think all your changes is now in the main branch, but I am not sure what we then should do with this pull request. Can't find a place to see if there are any differences.
I will try to get latest and build the main branch on my mac without any environments
Ah, I can see I have made my latest changes in my own fork. I will accept your changes, and sort out how my changes should be applied. Thx for contributing
Hi,
Thanks for open sourcing ben! I'm myself working on bridge and AI.
This PR aims to update Tensorflow to 2.0. It's useful since it's complicated to install tensorflow 1.15 with Python 3.7 since it's not supported by
conda-forge
anymore.I made the changes a while ago, so when I tried to open a PR at first a had a conflict with
sample.py
. My changes tosample.py
were something like (add alambda
function becausenumpy
complained):I was not able to run the current main branch locally with the following error:
I'm happy to make additional changes to this PR to make it work with Tensorflow 2.0 and Python 3.9+.