NameError: name 'poolA' is not defined

I am trying to tune this model

 def build_model(self, config):
        global convB2, drop2, convA2, poolA, poolB 
        window_size = 200
        self.x_gyro, self.x_acc, x_mag, q = load_data_train()
        self.Att_quat = Att_q(q)
        self.x_gyro_t, self.x_acc_t, x_mag_t, q_t = load_data_test()
        self.Att_quat_t = Att_q(q_t)

        self.x_gyro, self.x_acc, self.Att_quat = shuffle(self.x_gyro, self.x_acc, self.Att_quat)
        x1 = Input((window_size, 3), name='x1')
        x2 = Input((window_size, 3), name='x2')
        convA1 = Conv1D(config["Conv1DA"],11,padding='same',activation='relu')(x1)
        for i in range(config["Conv1DAn"]):
            if i > 0: 
                convA2 = Conv1D(config[f'Conv1DAn_{i}'],11,padding='same',activation='relu')(convA1)
                poolA = MaxPooling1D(3)(convA2)
            #elif i == 0: 
             #   poolA = MaxPooling1D(3)(convA1)
            else:
                poolA = MaxPooling1D(3)(convA1)
        
        
        convB1 = Conv1D(config["Conv1DB"],11,padding='same',activation='relu')(x2)
        for i in range(config["Conv1DBn"]):
            if i > 0:
                convB2 = Conv1D(config[f'Conv1DBn_{i}'],11,padding='same',activation='relu')(convB1)
                poolB = MaxPooling1D(3)(convB2)
            #elif i == 0: 
            #    poolB = MaxPooling1D(3)(convB1)
            else:
                poolB = MaxPooling1D(3)(convB1)
        AB = concatenate([poolA, poolB])
        
        lstm1 = Bidirectional(LSTM(config["LSTM1"], return_sequences=True))(AB)
        drop1 = Dropout(config['dropout'])(lstm1)
        for i in range(config['LSTMn']):
            if i > 0:
                lstm2 = Bidirectional(LSTM(config[f'LSTMn_{i}'], return_sequences=True))(drop1)
                drop1 =  Dropout(config['dropout'])(lstm2)   
        lstm2 = Bidirectional(LSTM(config['LSTMn_l']))(drop1)
        drop2 =  Dropout(config['dropout'])(lstm2)
        y1_pred = Dense(4,kernel_regularizer='l2')(drop2)
        model = Model(inputs =[x1, x2], outputs = [y1_pred])
        #model.compile(loss='mse', optimizer='adam')
        return model

But sometimes and randomly I got these error

1.>

Failure # 1 (occurred at 2022-09-05_05-24-12)
Traceback (most recent call last):
File “/home/ssrc/asq/lib/python3.8/site-packages/ray/tune/execution/ray_trial_executor.py”, line 989, in get_next_executor_event
future_result = ray.get(ready_future)
File “/home/ssrc/asq/lib/python3.8/site-packages/ray/_private/client_mode_hook.py”, line 105, in wrapper
return func(*args, **kwargs)
File “/home/ssrc/asq/lib/python3.8/site-packages/ray/_private/worker.py”, line 2277, in get
raise value
ray.exceptions.RayActorError: The actor died because of an error raised in its creation task, e[36mray::ResourceTrainable.init()e[39m (pid=1441131, ip=192.168.91.120, repr=<ray.tune.trainable.util.BroadModel object at 0x7fdf6cb67ca0>)
File “/home/ssrc/asq/lib/python3.8/site-packages/ray/tune/trainable/trainable.py”, line 157, in init
self.setup(copy.deepcopy(self.config))
File “ray_test.py”, line 242, in setup
model = self.build_model(config)
File “ray_test.py”, line 226, in build_model
AB = concatenate([poolA, poolB])
UnboundLocalError: local variable ‘poolA’ referenced before assignment

Failure # 1 (occurred at 2022-09-05_05-28-20)
Traceback (most recent call last):
File “/home/ssrc/asq/lib/python3.8/site-packages/ray/tune/execution/ray_trial_executor.py”, line 989, in get_next_executor_event
future_result = ray.get(ready_future)
File “/home/ssrc/asq/lib/python3.8/site-packages/ray/_private/client_mode_hook.py”, line 105, in wrapper
return func(*args, **kwargs)
File “/home/ssrc/asq/lib/python3.8/site-packages/ray/_private/worker.py”, line 2277, in get
raise value
ray.exceptions.RayActorError: The actor died because of an error raised in its creation task, e[36mray::ResourceTrainable.init()e[39m (pid=1444770, ip=192.168.91.120, repr=<ray.tune.trainable.util.BroadModel object at 0x7f099dabbc10>)
File “/home/ssrc/asq/lib/python3.8/site-packages/ray/tune/trainable/trainable.py”, line 157, in init
self.setup(copy.deepcopy(self.config))
File “ray_test.py”, line 242, in setup
model = self.build_model(config)
File “ray_test.py”, line 226, in build_model
AB = concatenate([poolA, poolB])
NameError: name ‘poolB’ is not defined

Hi @Arman_Asgharpoor,

Is it possible that

config["Conv1DAn"]

is 0 or negative?

For either of those cases your range will be an empty iterable and poolA will not be defined.