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

Support Apple Silicon #136

Closed
tribustale opened this issue Jan 28, 2021 · 6 comments
Closed

Support Apple Silicon #136

tribustale opened this issue Jan 28, 2021 · 6 comments

Comments

@tribustale
Copy link

Hi, is it possible that this library one day will be usable in the new generation of architecture Apple Silicon M1?

I tried to install it in a conda environment (through miniforge) after having installed also TensorFlow 2.4 benchmark on Mac M1, but it doesn't work! It gives an error related with bazel.

@alvarosg
Copy link
Collaborator

alvarosg commented Feb 1, 2021

Thank your for your message. Is the problem related to this library specifically, or are you having troubles in general running any TensorFlow code on the hardware?

@tribustale
Copy link
Author

I tried in three different ways;

  • installing tensorflow_macos for the new arm64 architecture in a virtual environment: in this way tensorflow2.4 works but graph_nets cannot be imported due to problem installing bazel;
  • installing tensorflow_macos for the old x86_64 architecture: in this way graph_nets can be installed but when I call tensorflow my jupyter kernel crashes;
  • installing tensorflow from source, using terminal with Rosetta2, I can install graph_nets but tensorflow again crashes.

@alvarosg
Copy link
Collaborator

alvarosg commented Feb 2, 2021

Could you share the full stack trace when importing graph_nets in the first case? Which line of the import fails?

I think it tensorflow works, then graph_nets should work, since graph_nets is pure python, so if it fails with a bazel related problem, this probably means tensorflow does not fully work.

@tribustale
Copy link
Author

In the first case, using a jupyter-lab notebook I run

install_graph_nets_library = "Yes"  #@param ["Yes", "No"]

if install_graph_nets_library.lower() == "yes":
  print("Installing Graph Nets library and dependencies:")
  print("Output message from command:\n")
  !pip install "graph_nets>=1.1" "dm-sonnet>=2.0.0b0"
else:
  print("Skipping installation of Graph Nets library")

and everything goes fine. All the following packages seem installed:

  • graph_nets (1.1.0)
  • dm-sonnet (2.0.0)
  • wrapt (1.12.1)
  • dm-tree (0.1.5)
  • tabulate (0.8.7)
  • numpy (1.18.5)
  • absl-py (0.11.0)
  • six (1.15.0)
  • networkx (2.5)
  • setuptools (53.0.0)
  • future (0.18.2)
  • decorator (4.4.2)
  • tensorflow_probability (0.12.1).

It appears that pip doesn't find tensorflow, since when running:

pip show tensorflow 

comes out

WARNING: Package(s) not found: tensorflow

even tough tensorflow is installed through tensorflow_macos. This is confirmed by importing tensorflow into the notebook:

import tensorflow as tf
tf.__version__

'2.4.0-rc0'

but when running

from graph_nets import utils_np
from graph_nets import utils_tf
from graph_nets import modules

the following error comes up :

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/tdametta/lib/python3.8/site-packages/tensorflow/python/autograph/impl/api.py in to_graph(entity, recursive, experimental_optional_features)
    748             optional_features=experimental_optional_features))
--> 749     return autograph_artifact(_convert_actual(entity, program_ctx))
    750   except (ValueError, AttributeError, KeyError, NameError, AssertionError) as e:

~/tdametta/lib/python3.8/site-packages/tensorflow/python/autograph/impl/api.py in _convert_actual(entity, program_ctx)
    283 
--> 284   transformed, module, source_map = _TRANSPILER.transform(entity, program_ctx)
    285 

~/tdametta/lib/python3.8/site-packages/tensorflow/python/autograph/pyct/transpiler.py in transform(self, obj, user_context)
    285     if inspect.isfunction(obj) or inspect.ismethod(obj):
--> 286       return self.transform_function(obj, user_context)
    287 

~/tdametta/lib/python3.8/site-packages/tensorflow/python/autograph/pyct/transpiler.py in transform_function(self, fn, user_context)
    469           # TODO(mdan): Confusing overloading pattern. Fix.
--> 470           nodes, ctx = super(PyToPy, self).transform_function(fn, user_context)
    471 

~/tdametta/lib/python3.8/site-packages/tensorflow/python/autograph/pyct/transpiler.py in transform_function(self, fn, user_context)
    362     node = self._erase_arg_defaults(node)
--> 363     result = self.transform_ast(node, context)
    364 

~/tdametta/lib/python3.8/site-packages/tensorflow/python/autograph/impl/api.py in transform_ast(self, node, ctx)
    251     unsupported_features_checker.verify(node)
--> 252     node = self.initial_analysis(node, ctx)
    253 

~/tdametta/lib/python3.8/site-packages/tensorflow/python/autograph/impl/api.py in initial_analysis(self, node, ctx)
    238     graphs = cfg.build(node)
--> 239     node = qual_names.resolve(node)
    240     node = activity.resolve(node, ctx, None)

~/tdametta/lib/python3.8/site-packages/tensorflow/python/autograph/pyct/qual_names.py in resolve(node)
    251 def resolve(node):
--> 252   return QnResolver().visit(node)
    253 

/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ast.py in visit(self, node)
    359         visitor = getattr(self, method, self.generic_visit)
--> 360         return visitor(node)
    361 

/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ast.py in generic_visit(self, node)
    444             elif isinstance(old_value, AST):
--> 445                 new_node = self.visit(old_value)
    446                 if new_node is None:

/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ast.py in visit(self, node)
    359         visitor = getattr(self, method, self.generic_visit)
--> 360         return visitor(node)
    361 

/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ast.py in generic_visit(self, node)
    435                     if isinstance(value, AST):
--> 436                         value = self.visit(value)
    437                         if value is None:

/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ast.py in visit(self, node)
    359         visitor = getattr(self, method, self.generic_visit)
--> 360         return visitor(node)
    361 

~/tdametta/lib/python3.8/site-packages/tensorflow/python/autograph/pyct/qual_names.py in visit_Name(self, node)
    216   def visit_Name(self, node):
--> 217     node = self.generic_visit(node)
    218     anno.setanno(node, anno.Basic.QN, QN(node.id))

/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ast.py in generic_visit(self, node)
    444             elif isinstance(old_value, AST):
--> 445                 new_node = self.visit(old_value)
    446                 if new_node is None:

/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ast.py in visit(self, node)
    359         visitor = getattr(self, method, self.generic_visit)
--> 360         return visitor(node)
    361 

~/tdametta/lib/python3.8/site-packages/tensorflow/python/autograph/pyct/qual_names.py in visit_Subscript(self, node)
    231     s = node.slice
--> 232     if not isinstance(s, gast.Index):
    233       # TODO(mdan): Support range and multi-dimensional indices.

AttributeError: module 'gast' has no attribute 'Index'

During handling of the above exception, another exception occurred:

ConversionError                           Traceback (most recent call last)
<ipython-input-39-29055414a904> in <module>
----> 1 from graph_nets import utils_np
      2 from graph_nets import utils_tf
      3 from graph_nets import modules

~/tdametta/lib/python3.8/site-packages/graph_nets/__init__.py in <module>
     19 from __future__ import print_function
     20 
---> 21 from graph_nets import blocks
     22 from graph_nets import graphs
     23 from graph_nets import modules

~/tdametta/lib/python3.8/site-packages/graph_nets/blocks.py in <module>
     33 from __future__ import print_function
     34 
---> 35 from graph_nets import _base
     36 from graph_nets import graphs
     37 from graph_nets import utils_tf

~/tdametta/lib/python3.8/site-packages/graph_nets/_base.py in <module>
     51 
     52 import six
---> 53 import sonnet as snt
     54 
     55 _sonnet_version = snt.__version__

~/tdametta/lib/python3.8/site-packages/sonnet/__init__.py in <module>
     19 from __future__ import print_function
     20 
---> 21 from sonnet import distribute
     22 from sonnet import initializers
     23 from sonnet import mixed_precision

~/tdametta/lib/python3.8/site-packages/sonnet/distribute.py in <module>
     19 from __future__ import print_function
     20 
---> 21 from sonnet.src.distribute.batch_norm import CrossReplicaBatchNorm
     22 from sonnet.src.distribute.replicator import create_variables_eagerly
     23 from sonnet.src.distribute.replicator import Replicator

~/tdametta/lib/python3.8/site-packages/sonnet/src/distribute/batch_norm.py in <module>
     20 from __future__ import print_function
     21 
---> 22 from sonnet.src import batch_norm
     23 from sonnet.src import initializers
     24 from sonnet.src import metrics

~/tdametta/lib/python3.8/site-packages/sonnet/src/batch_norm.py in <module>
     32 
     33 
---> 34 class BaseBatchNorm(base.Module):
     35   r"""Batch normalization module.
     36 

~/tdametta/lib/python3.8/site-packages/sonnet/src/batch_norm.py in BaseBatchNorm()
    130 
    131   @utils.smart_autograph
--> 132   def __call__(self,
    133                inputs: tf.Tensor,
    134                is_training: types.BoolLike,

~/tdametta/lib/python3.8/site-packages/sonnet/src/utils.py in smart_autograph(f)
    178     A wrapper for `f` that dispatches to the original or autograph version of f.
    179   """
--> 180   f_autograph = tf.autograph.to_graph(f)
    181 
    182   @functools.wraps(f)

~/tdametta/lib/python3.8/site-packages/tensorflow/python/autograph/impl/api.py in to_graph(entity, recursive, experimental_optional_features)
    750   except (ValueError, AttributeError, KeyError, NameError, AssertionError) as e:
    751     logging.error(1, 'Error converting %s', entity, exc_info=True)
--> 752     raise ConversionError('converting {}: {}: {}'.format(
    753         entity, e.__class__.__name__, str(e)))
    754 

ConversionError: converting <function BaseBatchNorm.__call__ at 0x124539ca0>: AttributeError: module 'gast' has no attribute 'Index'

What should I try? It appears it has a problem with gast and the new version 0.4 (that doesn't have .Index()), I tried with downgrade to 0.3.3 but it doesn't change.

@alvarosg
Copy link
Collaborator

alvarosg commented Feb 8, 2021

The problem seems to happen when importing sonnet, so I would recommend to try to reproduce the error just by importing and installing sonnet, and if it still happens, raise an issue against the sonnet repo.

@alvarosg
Copy link
Collaborator

(closing due to inactivity)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants