threestudio-project / threestudio

A unified framework for 3D content generation.
Apache License 2.0
5.98k stars 463 forks source link

Syntax error #62

Closed softmurata closed 1 year ago

softmurata commented 1 year ago

Thanks for great work. I would like to run inference with stable diffusion on google colab, but I met the following error.

inference script

%cd /content/threestudio
!python launch.py --config configs/dreamfusion-sd.yaml --train --gpu 0 system.prompt_processor.prompt="a zoomed out DSLR photo of a baby bunny sitting on top of a stack of pancakes"

Error

╭───────────────────── Traceback (most recent call last) ──────────────────────╮
│ /content/threestudio/launch.py:157 in <module>                               │
│                                                                              │
│   154                                                                        │
│   155                                                                        │
│   156 if __name__ == "__main__":                                             │
│ ❱ 157 │   main()                                                             │
│   158                                                                        │
│                                                                              │
│ /content/threestudio/launch.py:82 in main                                    │
│                                                                              │
│    79 │   │                                                                  │
│    80 │   │   install_import_hook("threestudio", "typeguard.typechecked")    │
│    81 │                                                                      │
│ ❱  82 │   import threestudio                                                 │
│    83 │   from threestudio.utils.callbacks import (                          │
│    84 │   │   CodeSnapshotCallback,                                          │
│    85 │   │   ConfigSnapshotCallback,                                        │
│                                                                              │
│ /content/threestudio/threestudio/__init__.py:28 in <module>                  │
│                                                                              │
│   25 warn = rank_zero_warn                                                   │
│   26                                                                         │
│   27                                                                         │
│ ❱ 28 from . import data, models, systems                                     │
│   29                                                                         │
│                                                                              │
│ /content/threestudio/threestudio/models/__init__.py:1 in <module>            │
│                                                                              │
│ ❱ 1 from . import background, geometry, guidance, materials, prompt_processo │
│   2                                                                          │
│                                                                              │
│ /content/threestudio/threestudio/models/materials/__init__.py:1 in <module>  │
│                                                                              │
│ ❱ 1 from . import (                                                          │
│   2 │   base,                                                                │
│   3 │   diffuse_with_point_light_material,                                   │
│   4 │   neural_radiance_material,                                            │
│                                                                              │
│ /content/threestudio/threestudio/models/materials/no_material.py:16 in       │
│ <module>                                                                     │
│                                                                              │
│   13                                                                         │
│   14                                                                         │
│   15 @threestudio.register("no-material")                                    │
│ ❱ 16 class NoMaterial(BaseMaterial):                                         │
│   17 │   @dataclass                                                          │
│   18 │   class Config(BaseMaterial.Config):                                  │
│   19 │   │   n_output_dims: int = 3                                          │
│                                                                              │
│ /content/threestudio/threestudio/models/materials/no_material.py:40 in       │
│ NoMaterial                                                                   │
│                                                                              │
│   37 │   │   │   self.use_network = True                                     │
│   38 │                                                                       │
│   39 │   @typechecker                                                        │
│ ❱ 40 │   def forward(                                                        │
│   41 │   │   self, features: Float[Tensor, "B ... Nf"], **kwargs             │
│   42 │   ) -> Float[Tensor, "B ... Nc"]:                                     │
│   43 │   │   if not self.use_network:                                        │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_decorators.py:213 in      │
│ typechecked                                                                  │
│                                                                              │
│   210 │   │   wrapper_class = target.__class__                               │
│   211 │   │   target = target.__func__                                       │
│   212 │                                                                      │
│ ❱ 213 │   retval = instrument(target)                                        │
│   214 │   if isinstance(retval, str):                                        │
│   215 │   │   warn(                                                          │
│   216 │   │   │   f"{retval} -- not typechecking {function_name(target)}",   │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_decorators.py:54 in       │
│ instrument                                                                   │
│                                                                              │
│    51 │   module_source = inspect.getsource(sys.modules[f.__module__])       │
│    52 │   module_ast = ast.parse(module_source)                              │
│    53 │   instrumentor = TypeguardTransformer(target_path)                   │
│ ❱  54 │   instrumentor.visit(module_ast)                                     │
│    55 │                                                                      │
│    56 │   if global_config.debug_instrumentation and sys.version_info >= (3, │
│    57 │   │   # Find the matching AST node, then unparse it to source and pr │
│                                                                              │
│ /usr/lib/python3.10/ast.py:418 in visit                                      │
│                                                                              │
│    415 │   │   """Visit a node."""                                           │
│    416 │   │   method = 'visit_' + node.__class__.__name__                   │
│    417 │   │   visitor = getattr(self, method, self.generic_visit)           │
│ ❱  418 │   │   return visitor(node)                                          │
│    419 │                                                                     │
│    420 │   def generic_visit(self, node):                                    │
│    421 │   │   """Called if no explicit visitor function exists for a node." │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_transformer.py:570 in     │
│ visit_Module                                                                 │
│                                                                              │
│    567 │   │   return node                                                   │
│    568 │                                                                     │
│    569 │   def visit_Module(self, node: Module) -> Module:                   │
│ ❱  570 │   │   self.generic_visit(node)                                      │
│    571 │   │   self._memo.insert_imports(node)                               │
│    572 │   │                                                                 │
│    573 │   │   fix_missing_locations(node)                                   │
│                                                                              │
│ /usr/lib/python3.10/ast.py:494 in generic_visit                              │
│                                                                              │
│    491 │   │   │   │   new_values = []                                       │
│    492 │   │   │   │   for value in old_value:                               │
│    493 │   │   │   │   │   if isinstance(value, AST):                        │
│ ❱  494 │   │   │   │   │   │   value = self.visit(value)                     │
│    495 │   │   │   │   │   │   if value is None:                             │
│    496 │   │   │   │   │   │   │   continue                                  │
│    497 │   │   │   │   │   │   elif not isinstance(value, AST):              │
│                                                                              │
│ /usr/lib/python3.10/ast.py:418 in visit                                      │
│                                                                              │
│    415 │   │   """Visit a node."""                                           │
│    416 │   │   method = 'visit_' + node.__class__.__name__                   │
│    417 │   │   visitor = getattr(self, method, self.generic_visit)           │
│ ❱  418 │   │   return visitor(node)                                          │
│    419 │                                                                     │
│    420 │   def generic_visit(self, node):                                    │
│    421 │   │   """Called if no explicit visitor function exists for a node." │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_transformer.py:615 in     │
│ visit_ClassDef                                                               │
│                                                                              │
│    612 │   │   │   │   │   │   │   {kw.arg: kw.value for kw in decorator.key │
│    613 │   │   │   │   │   │   )                                             │
│    614 │   │   │                                                             │
│ ❱  615 │   │   │   self.generic_visit(node)                                  │
│    616 │   │   │   return node                                               │
│    617 │                                                                     │
│    618 │   def visit_FunctionDef(                                            │
│                                                                              │
│ /usr/lib/python3.10/ast.py:494 in generic_visit                              │
│                                                                              │
│    491 │   │   │   │   new_values = []                                       │
│    492 │   │   │   │   for value in old_value:                               │
│    493 │   │   │   │   │   if isinstance(value, AST):                        │
│ ❱  494 │   │   │   │   │   │   value = self.visit(value)                     │
│    495 │   │   │   │   │   │   if value is None:                             │
│    496 │   │   │   │   │   │   │   continue                                  │
│    497 │   │   │   │   │   │   elif not isinstance(value, AST):              │
│                                                                              │
│ /usr/lib/python3.10/ast.py:418 in visit                                      │
│                                                                              │
│    415 │   │   """Visit a node."""                                           │
│    416 │   │   method = 'visit_' + node.__class__.__name__                   │
│    417 │   │   visitor = getattr(self, method, self.generic_visit)           │
│ ❱  418 │   │   return visitor(node)                                          │
│    419 │                                                                     │
│    420 │   def generic_visit(self, node):                                    │
│    421 │   │   """Called if no explicit visitor function exists for a node." │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_transformer.py:644 in     │
│ visit_FunctionDef                                                            │
│                                                                              │
│    641 │   │   │   │   if self._memo.name_matches(decorator, *ignore_decorat │
│    642 │   │   │   │   │   return node                                       │
│    643 │   │                                                                 │
│ ❱  644 │   │   with self._use_memo(node):                                    │
│    645 │   │   │   arg_annotations: dict[str, Any] = {}                      │
│    646 │   │   │   if self._target_path is None or self._memo.path == self._ │
│    647 │   │   │   │   for decorator in node.decorator_list.copy():          │
│                                                                              │
│ /usr/lib/python3.10/contextlib.py:135 in __enter__                           │
│                                                                              │
│   132 │   │   # they are only needed for recreation, which is not possible a │
│   133 │   │   del self.args, self.kwds, self.func                            │
│   134 │   │   try:                                                           │
│ ❱ 135 │   │   │   return next(self.gen)                                      │
│   136 │   │   except StopIteration:                                          │
│   137 │   │   │   raise RuntimeError("generator didn't yield") from None     │
│   138                                                                        │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_transformer.py:525 in     │
│ _use_memo                                                                    │
│                                                                              │
│    522 │   │   │   │   │   │   │   │   items[2]                              │
│    523 │   │   │   │   │   │   │   )                                         │
│    524 │   │   │   │   else:                                                 │
│ ❱  525 │   │   │   │   │   new_memo.return_annotation = self._convert_annota │
│    526 │   │   │   │   │   │   return_annotation                             │
│    527 │   │   │   │   │   )                                                 │
│    528                                                                       │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_transformer.py:555 in     │
│ _convert_annotation                                                          │
│                                                                              │
│    552 │   │                                                                 │
│    553 │   │   # Convert PEP 604 unions (x | y) and generic built-in collect │
│    554 │   │   # necessary, and undo forward references                      │
│ ❱  555 │   │   new_annotation = cast(expr, AnnotationTransformer(self).visit │
│    556 │   │   if isinstance(new_annotation, expr):                          │
│    557 │   │   │   new_annotation = ast.copy_location(new_annotation, annota │
│    558                                                                       │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_transformer.py:343 in     │
│ visit                                                                        │
│                                                                              │
│    340 │   │   self._memo = transformer._memo                                │
│    341 │                                                                     │
│    342 │   def visit(self, node: AST) -> Any:                                │
│ ❱  343 │   │   new_node = super().visit(node)                                │
│    344 │   │   if isinstance(new_node, Expression) and not hasattr(new_node, │
│    345 │   │   │   return None                                               │
│    346                                                                       │
│                                                                              │
│ /usr/lib/python3.10/ast.py:418 in visit                                      │
│                                                                              │
│    415 │   │   """Visit a node."""                                           │
│    416 │   │   method = 'visit_' + node.__class__.__name__                   │
│    417 │   │   visitor = getattr(self, method, self.generic_visit)           │
│ ❱  418 │   │   return visitor(node)                                          │
│    419 │                                                                     │
│    420 │   def generic_visit(self, node):                                    │
│    421 │   │   """Called if no explicit visitor function exists for a node." │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_transformer.py:400 in     │
│ visit_Subscript                                                              │
│                                                                              │
│    397 │   │   │   │   │   # forward reference                               │
│    398 │   │   │   │   │   items = [self.visit(slice_value.elts[0])] + slice │
│    399 │   │   │   │   else:                                                 │
│ ❱  400 │   │   │   │   │   items = [self.visit(item) for item in slice_value │
│    401 │   │   │   │                                                         │
│    402 │   │   │   │   # If this is a Union and any of the items is None, er │
│    403 │   │   │   │   # annotation                                          │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_transformer.py:400 in     │
│ <listcomp>                                                                   │
│                                                                              │
│    397 │   │   │   │   │   # forward reference                               │
│    398 │   │   │   │   │   items = [self.visit(slice_value.elts[0])] + slice │
│    399 │   │   │   │   else:                                                 │
│ ❱  400 │   │   │   │   │   items = [self.visit(item) for item in slice_value │
│    401 │   │   │   │                                                         │
│    402 │   │   │   │   # If this is a Union and any of the items is None, er │
│    403 │   │   │   │   # annotation                                          │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_transformer.py:343 in     │
│ visit                                                                        │
│                                                                              │
│    340 │   │   self._memo = transformer._memo                                │
│    341 │                                                                     │
│    342 │   def visit(self, node: AST) -> Any:                                │
│ ❱  343 │   │   new_node = super().visit(node)                                │
│    344 │   │   if isinstance(new_node, Expression) and not hasattr(new_node, │
│    345 │   │   │   return None                                               │
│    346                                                                       │
│                                                                              │
│ /usr/lib/python3.10/ast.py:418 in visit                                      │
│                                                                              │
│    415 │   │   """Visit a node."""                                           │
│    416 │   │   method = 'visit_' + node.__class__.__name__                   │
│    417 │   │   visitor = getattr(self, method, self.generic_visit)           │
│ ❱  418 │   │   return visitor(node)                                          │
│    419 │                                                                     │
│    420 │   def generic_visit(self, node):                                    │
│    421 │   │   """Called if no explicit visitor function exists for a node." │
│                                                                              │
│ /usr/local/lib/python3.10/dist-packages/typeguard/_transformer.py:451 in     │
│ visit_Constant                                                               │
│                                                                              │
│    448 │                                                                     │
│    449 │   def visit_Constant(self, node: Constant) -> Any:                  │
│    450 │   │   if isinstance(node.value, str):                               │
│ ❱  451 │   │   │   expression = ast.parse(node.value, mode="eval")           │
│    452 │   │   │   new_node = self.visit(expression)                         │
│    453 │   │   │   if new_node:                                              │
│    454 │   │   │   │   return copy_location(new_node.body, node)             │
│                                                                              │
│ /usr/lib/python3.10/ast.py:50 in parse                                       │
│                                                                              │
│     47 │   elif feature_version is None:                                     │
│     48 │   │   feature_version = -1                                          │
│     49 │   # Else it should be an int giving the minor version for 3.x.      │
│ ❱   50 │   return compile(source, filename, mode, flags,                     │
│     51 │   │   │   │      _feature_version=feature_version)                  │
│     52                                                                       │
│     53                                                                       │
╰──────────────────────────────────────────────────────────────────────────────╯
╭──────────────────────────────────────────────────────────────────────────────╮
│ B ... Nc                                                                     │
│   ▲                                                                          │
╰──────────────────────────────────────────────────────────────────────────────╯
SyntaxError: invalid syntax

Please give me some ideas?

thuliu-yt16 commented 1 year ago

It seems quite weird. I guess python3.10 may check the type hint syntax differently from the previous version. Give me some time to test it. Until then, you can run it without errors on python3.8 if it is possible to specify the python version on colab.

thuliu-yt16 commented 1 year ago

I can run the command without errors with python 3.10.11. Could you provide your environment, especially the version of typeguard and jaxtyping?

BTW, typeguard 4.0.0 and jaxtyping 0.2.19 work for me.

softmurata commented 1 year ago

Thanks for reply. In google colab, typeguard 4.0.0 and jaxtyping 0.2.19 are all OK. I comment out @typechecker on the forward().... and work fine. Maybe This problem is about python3.10....

bennyguo commented 1 year ago

I think it's fixed in this commit. Please consider updating to the latest code.