def componentnametoindices(componentname): componentorder = ['M0', 'M1', 'M2', 'M3',…
- User
def component_name_to_indices(component_name): component_order = ['M0', 'M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'C0', 'I0', 'V1'] return component_order.index(component_name) + 7 # Adjust 7 based on your actual structure
class EnhancedGNNModelWithSharedParams(torch.nn.Module): def init(self, num_node_features, num_edge_features, num_out_features): print("EnhancedGNNModelWithSharedParams init arguments:", num_node_features, num_edge_features, num_out_features) super(EnhancedGNNModelWithSharedParams, self).init() self.conv1 = GATConv(num_node_features, 8, heads=8, dropout=0.6)
nn_model = Sequential(Linear(num_edge_features, 32), ReLU(), Linear(32, 8 * 8)) self.conv2 = NNConv(8 * 8, num_out_features, nn_model, aggr='mean') def forward(self, node_features, edge_index, edge_attr): # Apply adjustment of shared parameters integrated within the model class modified_node_features = self.adjust_node_features(node_features) x = F.dropout(modified_node_features, p=0.6, training=self.training) x = F.elu(self.conv1(x, edge_index)) x = self.conv2(x, edge_index, edge_attr) print(f"GNN Model Output Shape: {x.shape}") # Debug print statement return x def adjust_node_features(self, node_features_tensor): # Filters out component nodes based on the ‘device_type’ feature component_mask = node_features_tensor[:, 0] == 0.0 node_features = node_features_tensor[component_mask] # Pairs for shared ‘w_value’ and ‘l_value’ pairs = [('M0', 'M1'), ('M2', 'M3'), ('M4', 'M7')] for pair in pairs: # Identify indices for the pair components indices = [component_name_to_indices(component) for component in pair] value_indices = [18, 19] # Assuming these are the indices for ‘w_value’, ‘l_value’ for i in indices[1:]: # Start from the second component of the pair first_component_mask = node_features[:, indices[0]] == 1.0 other_component_mask = node_features[:, i] == 1.0 if torch.any(first_component_mask) and torch.any(other_component_mask): # Adjust values of the other components within the pair to match the first #other_values = node_features[other_component_mask][:, value_indices] #first_values = node_features[first_component_mask][:, value_indices][0] #other_values[:] = first_values node_features[other_component_mask][:, value_indices] = node_features[first_component_mask][:, value_indices][0] return node_featuresclass Actor(nn.Module): def init(self, num_input_features, action_dim, std): super(Actor, self).init() print("Actor init arguments:", num_input_features, action_dim, std) # Define the actor model self.actor = nn.Sequential( nn.Linear(num_input_features, 64), nn.Tanh(), nn.Linear(64, 64), nn.Tanh(), nn.Linear(64, action_dim), ) self.log_std = nn.Parameter(torch.ones(1, action_dim) * std)
- Assistant
- User
File d:\opamp circuits\rl_gnn\rl_gnn_cktenv_new2.py:519 agent = PPOAgent(actor, critic, gnn_model, action_dim, bounds_low, bounds_high, lr_actor, lr_critic, gamma, lambda_, epsilon, std)
File d:\opamp circuits\rl_gnn\rl_gnn_cktenv_new2.py:323 in init self.actor = actor_class(gnn_model.conv2.out_channels, action_dim, std) # Initialize actor
File ~\anaconda3\envs\spyder\Lib\site-packages\torch\nn\modules\module.py:1520 in _call_impl return forward_call(*args, **kwargs)
TypeError: Actor.forward() takes 2 positional arguments but 4 were given
- Assistant
The error
TypeError: Actor.forward() takes 2 positional arguments but 4 were givenindicates that there is a misunderstanding about how the class is instantiated and used in your code. From your provided code snippets, the and its subsequent use doesn't directly show where you're calling explicitly with incorrect arguments. However, this error typically occurs when the method of a module (in this case, ) is passed a wrong number of arguments. - User
Here actor input feature dimention is 19 and the EnhancedGNNModelWithSharedParams input feature dimension is 24 will it create the error? check the following model output print statement results, and i verified all places where Actor is being used and nowhere passes extra arguments to an Actor instance.
Actor init arguments: 19 19 0.0 actor Actor( (actor): Sequential( (0): Linear(in_features=19, out_features=64, bias=True) (1): Tanh() (2): Linear(in_features=64, out_features=64, bias=True) (3): Tanh() (4): Linear(in_features=64, out_features=19, bias=True) ) ) EnhancedGNNModelWithSharedParams init arguments: 24 11 19 nn_model Sequential( (0): Linear(in_features=11, out_features=32, bias=True) (1): ReLU() (2): Linear(in_features=32, out_features=64, bias=True) ) Initializing Actor with output feature size: 19 GNN Model Conv2 Out Channels: 19 Action Dimension: 19 gnn_model EnhancedGNNModelWithSharedParams( (conv1): GATConv(24, 8, heads=8) (conv2): NNConv(64, 19, aggr=mean, nn=Sequential( (0): Linear(in_features=11, out_features=32, bias=True) (1): ReLU() (2): Linear(in_features=32, out_features=64, bias=True) )) )
- Assistant
- User
- Assistant
- User
- Assistant
- User
this updation will makes the model becomes under which category?
Giving All Nodes and Node Features to the Model for Selective Tuning During Training or Preprocessing Selective Nodes and Features for Tuning
- Assistant
- User
- Assistant