@@ -236,7 +236,7 @@ def accept(self, visitor: "ASTVisitor") -> Any:
236236class MemoryLimitStatement (Statement ):
237237 """Represents a memory limit statement: memory_limit: 64 MB"""
238238
239- limit_mb : int
239+ limit_mb : ConstrainedInt = field ( default_factory = lambda : ConstrainedInt ( 64 , 16 , 10000 ))
240240
241241 def accept (self , visitor : "ASTVisitor" ) -> Any :
242242 return visitor .visit_memory_limit_statement (self )
@@ -323,11 +323,11 @@ def accept(self, visitor: "ASTVisitor") -> Any:
323323class LayerDeclaration (Statement ):
324324 """Base class for layer declarations with type validation."""
325325
326- name : str = field ()
327- layer_type : LayerType = field ()
326+ name : str = ""
327+ layer_type : LayerType = LayerType . CONV2D
328328 parameters : Dict [str , Any ] = field (default_factory = dict )
329- source_line : Optional [int ] = field ( default = None )
330- source_column : Optional [int ] = field ( default = None )
329+ source_line : Optional [int ] = None
330+ source_column : Optional [int ] = None
331331
332332 def __post_init__ (self ):
333333 """Post-initialization hook for subclasses."""
@@ -345,12 +345,12 @@ def validate_parameters(self) -> List[str]:
345345class Conv2DDeclaration (LayerDeclaration ):
346346 """Conv2D layer with type-constrained parameters."""
347347
348- filters : ConstrainedInt = field ()
349- kernel_size : KernelSize = field ()
348+ filters : ConstrainedInt = field (default_factory = lambda : ConstrainedInt ( 32 ) )
349+ kernel_size : KernelSize = field (default_factory = lambda : KernelSize ( 3 ) )
350350 strides : StrideValue = field (default_factory = lambda : StrideValue (1 ))
351- padding : PaddingType = field ( default = PaddingType .VALID )
352- activation : ActivationType = field ( default = ActivationType .LINEAR )
353- use_bias : bool = field ( default = True )
351+ padding : PaddingType = PaddingType .VALID
352+ activation : ActivationType = ActivationType .LINEAR
353+ use_bias : bool = True
354354
355355 def __post_init__ (self ):
356356 super ().__post_init__ ()
@@ -392,9 +392,9 @@ def validate_parameters(self) -> List[str]:
392392class DenseDeclaration (LayerDeclaration ):
393393 """Dense layer with type-constrained parameters."""
394394
395- units : ConstrainedInt = field ()
396- activation : ActivationType = field ( default = ActivationType .LINEAR )
397- use_bias : bool = field ( default = True )
395+ units : ConstrainedInt = field (default_factory = lambda : ConstrainedInt ( 128 ) )
396+ activation : ActivationType = ActivationType .LINEAR
397+ use_bias : bool = True
398398
399399 def __post_init__ (self ):
400400 super ().__post_init__ ()
@@ -421,7 +421,7 @@ def validate_parameters(self) -> List[str]:
421421class DropoutDeclaration (LayerDeclaration ):
422422 """Dropout layer with type-constrained parameters."""
423423
424- rate : DropoutRate = field ()
424+ rate : DropoutRate = field (default_factory = lambda : DropoutRate ( 0.5 ) )
425425
426426 def __post_init__ (self ):
427427 super ().__post_init__ ()
@@ -444,9 +444,9 @@ def validate_parameters(self) -> List[str]:
444444class MaxPool2DDeclaration (LayerDeclaration ):
445445 """MaxPool2D layer with type-constrained parameters."""
446446
447- pool_size : Union [int , Tuple [int , int ]] = field ()
448- strides : Optional [StrideValue ] = field ( default = None )
449- padding : PaddingType = field ( default = PaddingType .VALID )
447+ pool_size : Union [int , Tuple [int , int ]] = 2
448+ strides : Optional [StrideValue ] = None
449+ padding : PaddingType = PaddingType .VALID
450450
451451 def __post_init__ (self ):
452452 super ().__post_init__ ()
@@ -697,7 +697,7 @@ def create_program_from_dict(config: Dict[str, Any]) -> Program:
697697 statements .append (OptimizeForStatement (goal = config ["optimize_for" ]))
698698
699699 if "memory_limit" in config :
700- statements .append (MemoryLimitStatement (limit_mb = config ["memory_limit" ]))
700+ statements .append (MemoryLimitStatement (limit_mb = ConstrainedInt ( config ["memory_limit" ], 16 , 10000 ) ))
701701
702702 if "enable_fusion" in config :
703703 statements .append (FusionStatement (enabled = config ["enable_fusion" ]))
@@ -749,7 +749,7 @@ def print_ast(node: ASTNode, indent: int = 0) -> str:
749749 elif isinstance (node , OptimizeForStatement ):
750750 result .append (f"{ prefix } OptimizeForStatement(goal='{ node .goal } ')" )
751751 elif isinstance (node , MemoryLimitStatement ):
752- result .append (f"{ prefix } MemoryLimitStatement(limit_mb={ node .limit_mb } )" )
752+ result .append (f"{ prefix } MemoryLimitStatement(limit_mb={ node .limit_mb . value } )" )
753753 elif isinstance (node , FusionStatement ):
754754 result .append (f"{ prefix } FusionStatement(enabled={ node .enabled } )" )
755755 elif isinstance (node , FrameworkStatement ):
0 commit comments