silverlight6 / TFTMuZeroAgent

Team fight tactics AI
Apache License 2.0
136 stars 33 forks source link

not running on Apple M1 hardware #4

Closed jacksonwalters closed 1 year ago

jacksonwalters commented 1 year ago

Tried running main with no modifications on Apple M1 hardware ([https://caffeinedev.medium.com/how-to-install-tensorflow-on-m1-mac-8e9b91d93706]), and receiving InvalidArgumentError: Incompatible shapes: [1,601] vs. [603] [Op:Mul] error.

(mlp) jacksonwalters@MacBook-Air TFTMuZeroAgent % python3 main.py
(1, -1)
(1, -1)
(2, -1)
(1, -1)
(3, -1)
(0, 0)
Metal device set to: Apple M1

systemMemory: 8.00 GB
maxCacheSize: 2.67 GB

2022-12-09 10:38:17.027767: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2022-12-09 10:38:17.027940: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>)
Traceback (most recent call last):
  File "main.py", line 14, in <module>
    main()
  File "main.py", line 10, in main
    AI_interface.train_model()
  File "/Users/jacksonwalters/Documents/GitHub/TFTMuZeroAgent/AI_interface.py", line 332, in train_model
    collect_gameplay_experience(game_sim, agents, buffers, episode_cnt)
  File "/Users/jacksonwalters/Documents/GitHub/TFTMuZeroAgent/AI_interface.py", line 252, in collect_gameplay_experience
    sim.episode(agent, buffers, episode_cnt)
  File "/Users/jacksonwalters/Documents/GitHub/TFTMuZeroAgent/game_round.py", line 443, in episode
    self.ai_buy_phase(player, agents[player.player_num], buffer[player.player_num], game_episode)
  File "/Users/jacksonwalters/Documents/GitHub/TFTMuZeroAgent/game_round.py", line 185, in ai_buy_phase
    action, policy = agent.policy(observation, player.player_num)
  File "/Users/jacksonwalters/Documents/GitHub/TFTMuZeroAgent/Models/MuZero_agent_2.py", line 504, in policy
    network_output = self.network.initial_inference(observation)
  File "/Users/jacksonwalters/Documents/GitHub/TFTMuZeroAgent/Models/MuZero_agent_2.py", line 110, in initial_inference
    value = self.value_encoder.decode(value_logits)
  File "/Users/jacksonwalters/Documents/GitHub/TFTMuZeroAgent/Models/MuZero_agent_2.py", line 352, in decode
    num_steps = tf.reduce_sum(logits * self.step_range_float, -1)
  File "/Users/jacksonwalters/miniforge3/envs/mlp/lib/python3.8/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/Users/jacksonwalters/miniforge3/envs/mlp/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 7186, in raise_from_not_ok_status
    raise core._status_to_exception(e) from None  # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [1,601] vs. [603] [Op:Mul]
jacksonwalters commented 1 year ago

self.step_range_float was 603, when it should've been 601. tracing the error, step_range_float depends on step_range_int which depends on num_steps. in line 344, num_steps = int(math.ceil(max_value) + 1 - math.floor(min_value)). max_value is a result of contractive mapping, which yields max_value=300.00012 and min_value=-300.00012. Applying ceil gives 301, floor gives -301. this gives a range of 603, which is wrong. swapping floor and ceil, we get max_value=300 and min_value=-300, which gives the correct range of 601 and allows the code to run.

this is likely not a hardware issue, but it is possible different hardware will yield small differences in the value of contractive mapping, perhaps 299.99988 and -299.99988 or something like that, so one must be careful here.