Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Terminating app due to uncaught exception 'NSRangeException' #99

Closed
tedlex opened this issue Dec 29, 2020 · 6 comments
Closed

Terminating app due to uncaught exception 'NSRangeException' #99

tedlex opened this issue Dec 29, 2020 · 6 comments

Comments

@tedlex
Copy link

tedlex commented Dec 29, 2020

Python crashed when I ran the code below
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array'
My code:

from tensorflow.keras.datasets import imdb
from tensorflow.keras.preprocessing import sequence
from tensorflow.keras.models import Sequential
from tensorflow.keras import layers
from tensorflow.keras.optimizers import RMSprop

max_features = 10000  # number of words to consider as features
max_len = 500  # cut texts after this number of words (among top max_features most common words)

print('Loading data...')
(x_train, y_train), (x_test, y_test) = imdb.load_data(num_words=max_features)
print(len(x_train), 'train sequences')
print(len(x_test), 'test sequences')

print('Pad sequences (samples x time)')
x_train = sequence.pad_sequences(x_train, maxlen=max_len)
x_test = sequence.pad_sequences(x_test, maxlen=max_len)
print('x_train shape:', x_train.shape)
print('x_test shape:', x_test.shape)

model = Sequential()
model.add(layers.Embedding(max_features, 128, input_length=max_len))
model.add(layers.Conv1D(32, 7, activation='relu'))
model.add(layers.MaxPooling1D(5))
model.add(layers.Conv1D(32, 7, activation='relu'))
model.add(layers.GlobalMaxPooling1D())
model.add(layers.Dense(1))

model.summary()

model.compile(optimizer=RMSprop(lr=1e-4),
              loss='binary_crossentropy',
              metrics=['acc'])
history = model.fit(x_train, y_train,
                    epochs=10,
                    batch_size=128,
                    validation_split=0.2)

However, when I ran

model = models.Sequential()
model.add(layers.Conv2D(32, (3, 3), activation='relu', 
                        input_shape=(28, 28, 1)))
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu')) 
model.add(layers.MaxPooling2D((2, 2)))
model.add(layers.Conv2D(64, (3, 3), activation='relu'))
model.add(layers.Flatten()) 
model.add(layers.Dense(64, activation='relu'))
model.add(layers.Dense(10, activation='softmax'))

from tensorflow.keras.datasets import mnist
from tensorflow.keras.utils import to_categorical

(train_images, train_labels), (test_images, test_labels) = \
                                                mnist.load_data()
train_images = train_images.reshape((60000, 28, 28, 1)) 
train_images = train_images.astype('float32') / 255
test_images = test_images.reshape((10000, 28, 28, 1)) 
test_images = test_images.astype('float32') / 255
train_labels = to_categorical(train_labels) 
test_labels = to_categorical(test_labels)

model.compile(optimizer='rmsprop', loss='categorical_crossentropy',
              metrics=['accuracy'])
model.fit(train_images, train_labels, epochs=5, batch_size=64)

Everything was fine, and it was accelerated by gpu successfully. What's wrong?

@anna-tikhonova
Copy link
Collaborator

Thank you very much for reporting this! We will investigate locally and report back.

@OliverUrbann
Copy link

I think I have the same problem (with different code):

2021-01-28 17:55:19.641 Python[41489:1137613] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff204836af __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007fff201bb3c9 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff20537a9a -[__NSCFString characterAtIndex:].cold.1 + 0
	3   CoreFoundation                      0x00007fff203f6e26 -[__NSArrayM objectAtIndexedSubscript:] + 142
	4   MLCompute                           0x00007fff2a02f66e -[MLCDeviceGPU(MLCEngineDispatch) dispatchForwardLayerWithStates:sourceTensor:secondaryTensor:resultTensor:resultTensorIsTemporary:resultStateIsTemporary:resultTensorAllocate:forTraining:] + 2375
	5   MLCompute                           0x00007fff2a02c238 -[MLCDeviceGPU(MLCEngineDispatch) dispatchForwardLayer:sourceTensor:secondaryTensor:resultTensor:resultTensorIsTemporary:resultTensorAllocate:] + 121
	6   MLCompute                           0x00007fff2a04a412 -[MLCTrainingGraph sumRootSourceGradientTensor:device:] + 756
	7   MLCompute                           0x00007fff2a04a970 -[MLCTrainingGraph sumAllRootSourceGradientTensors:] + 728
	8   MLCompute                           0x00007fff2a052a02 -[MLCTrainingGraph executeGradientFromLayerIndex:batchSize:] + 244
	9   MLCompute                           0x00007fff2a057547 -[MLCTrainingGraph executeGradientWithBatchSize:options:outputsData:completionHandler:] + 1000
	10  _pywrap_tensorflow_internal.so      0x000000011b138985 _ZN10tensorflow9mlcompute3ops13MLCSubgraphOp23ExecuteMLCTrainingGraphEPNS_15OpKernelContextEPNS1_27MLCSubgraphExecutionContextEj + 533
	11  _pywrap_tensorflow_internal.so      0x000000011b137cbe _ZN10tensorflow9mlcompute3ops13MLCSubgraphOp20ProcessMLCSubgraphOpEPNS_15OpKernelContextEPNS1_27MLCSubgraphExecutionContextE + 1168
	12  _pywrap_tensorflow_internal.so      0x000000011b13ac6a _ZN10tensorflow9mlcompute3ops13MLCSubgraphOp7ComputeEPNS_15OpKernelContextE + 1166
	13  libtensorflow_framework.2.dylib     0x000000012fd6b1c9 _ZN10tensorflow12_GLOBAL__N_113ExecutorStateINS_21SimplePropagatorStateEE7ProcessENS2_10TaggedNodeEx + 3717
	14  libtensorflow_framework.2.dylib     0x000000012fde6485 _ZN5Eigen15ThreadPoolTemplIN10tensorflow6thread16EigenEnvironmentEE10WorkerLoopEi + 605
	15  libtensorflow_framework.2.dylib     0x000000012fde6154 _ZZN10tensorflow6thread16EigenEnvironment12CreateThreadENSt3__18functionIFvvEEEENKUlvE_clEv + 66
	16  libtensorflow_framework.2.dylib     0x000000012fdd7b47 _ZN10tensorflow12_GLOBAL__N_17PThread8ThreadFnEPv + 97
	17  libsystem_pthread.dylib             0x00007fff20311950 _pthread_start + 224
	18  libsystem_pthread.dylib             0x00007fff2030d47b thread_start + 15
)
libc++abi.dylib: terminating with uncaught exception of type NSException 

@bezineb5
Copy link

bezineb5 commented Feb 2, 2021

I have the same issue in another context. Unfortunately, it's very difficult to give a minimal example:

2021-02-02 12:52:10.817 Python[64390:1367240] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
        0   CoreFoundation                      0x00000001a32bd320 __exceptionPreprocess + 240
        1   libobjc.A.dylib                     0x00000001a2febc04 objc_exception_throw + 60
        2   CoreFoundation                      0x00000001a3384064 -[__NSCFString characterAtIndex:].cold.1 + 0
        3   CoreFoundation                      0x00000001a322ba0c -[__NSArrayM objectAtIndexedSubscript:] + 188
        4   MLCompute                           0x00000001ac33a104 -[MLCTrainingGraph resultGradientTensorToUseByExecuteGradientForLayer:sourceIndex:incrementIntermediateIndex:] + 208
        5   MLCompute                           0x00000001ac33b598 -[MLCTrainingGraph allocateGradientTensorsForLayersInGraph:] + 660
        6   MLCompute                           0x00000001ac33c004 -[MLCTrainingGraph compileAndAllocateGradientTensorsForGraph:] + 140
        7   MLCompute                           0x00000001ac344708 -[MLCTrainingGraph executeGradientWithBatchSize:options:outputsData:completionHandler:] + 960
        8   _pywrap_tensorflow_internal.so      0x0000000139df90d8 _ZN10tensorflow9mlcompute7kernels13MLCSubgraphOp23ExecuteMLCTrainingGraphEPNS_15OpKernelContextEPNS1_10MLCContextEj + 568
        9   _pywrap_tensorflow_internal.so      0x0000000139df8280 _ZN10tensorflow9mlcompute7kernels13MLCSubgraphOp20ProcessMLCSubgraphOpEPNS_15OpKernelContextEPPNS1_10MLCContextEPPNS1_15TFContextStatusE + 432
        10  _pywrap_tensorflow_internal.so      0x0000000139dfabe4 _ZN10tensorflow9mlcompute7kernels13MLCSubgraphOp7ComputeEPNS_15OpKernelContextE + 804
        11  libtensorflow_framework.2.dylib     0x00000001060e13c0 _ZN10tensorflow12_GLOBAL__N_113ExecutorStateINS_15PropagatorStateEE7ProcessENS2_10TaggedNodeEx + 2868
        12  libtensorflow_framework.2.dylib     0x00000001060e268c _ZNSt3__110__function6__funcIZN10tensorflow12_GLOBAL__N_113ExecutorStateINS2_15PropagatorStateEE7RunTaskINS_6__bindIMS6_FvNS5_10TaggedNodeExEJPS6_RKS9_RxEEEEEvOT_EUlvE_NS_9allocatorISJ_EEFvvEEclEv + 80
        13  libtensorflow_framework.2.dylib     0x000000010615a520 _ZN5Eigen15ThreadPoolTemplIN10tensorflow6thread16EigenEnvironmentEE10WorkerLoopEi + 552
        14  libtensorflow_framework.2.dylib     0x000000010615a1f8 _ZZN10tensorflow6thread16EigenEnvironment12CreateThreadENSt3__18functionIFvvEEEENKUlvE_clEv + 80
        15  libtensorflow_framework.2.dylib     0x000000010614bae0 _ZN10tensorflow12_GLOBAL__N_17PThread8ThreadFnEPv + 104
        16  libsystem_pthread.dylib             0x00000001a314506c _pthread_start + 320
        17  libsystem_pthread.dylib             0x00000001a313fda0 thread_start + 8
)

@anna-tikhonova
Copy link
Collaborator

Please try the updated wheel (v0.1alpha2) and let us know if you are still seeing this issue. Thank you very much!

@bezineb5
Copy link

bezineb5 commented Feb 2, 2021

Unfortunately, I have the issue with the v0.1alpha2.

@andrew-twigg
Copy link

Also think I'm seeing this issue when running the network attached, using v0.1 a2.

net_and_freeze.zip

The network does train ok on an Nvidia GPU.

Application Specific Information:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndexedSubscript:]: index 0 beyond bounds for empty array'
terminating with uncaught exception of type NSException
abort() called

Application Specific Backtrace 1:
0 CoreFoundation 0x0000000190566320 __exceptionPreprocess + 240
1 libobjc.A.dylib 0x0000000190294c04 objc_exception_throw + 60
2 CoreFoundation 0x000000019062d064 -[__NSCFString characterAtIndex:].cold.1 + 0
3 CoreFoundation 0x00000001904d4a0c -[__NSArrayM objectAtIndexedSubscript:] + 188
4 MLCompute 0x000000019960256c -[MLCInferenceGraph executeWithInputsData:lossLabelsData:lossLabelWeightsData:outputsData:batchSize:options:completionHandler:] + 3908
5 MLCompute 0x0000000199601534 -[MLCInferenceGraph executeWithInputsData:outputsData:batchSize:options:completionHandler:] + 116
6 _pywrap_tensorflow_internal.so 0x000000010882a65c _ZN10tensorflow9mlcompute7kernels13MLCSubgraphOp24ExecuteMLCInferenceGraphEPNS_15OpKernelContextEPNS1_10MLCContextEj + 1580
7 _pywrap_tensorflow_internal.so 0x0000000108828498 _ZN10tensorflow9mlcompute7kernels13MLCSubgraphOp20ProcessMLCSubgraphOpEPNS_15OpKernelContextEPPNS1_10MLCContextEPPNS1_15TFContextStatusE + 968
8 _pywrap_tensorflow_internal.so 0x000000010882abe4 _ZN10tensorflow9mlcompute7kernels13MLCSubgraphOp7ComputeEPNS_15OpKernelContextE + 804
9 libtensorflow_framework.2.dylib 0x000000011bfab5e8 _ZN10tensorflow12_GLOBAL__N_113ExecutorStateINS_21SimplePropagatorStateEE7ProcessENS2_10TaggedNodeEx + 2772
10 libtensorflow_framework.2.dylib 0x000000011c01e520 _ZN5Eigen15ThreadPoolTemplIN10tensorflow6thread16EigenEnvironmentEE10WorkerLoopEi + 552
11 libtensorflow_framework.2.dylib 0x000000011c01e1f8 _ZZN10tensorflow6thread16EigenEnvironment12CreateThreadENSt3__18functionIFvvEEEENKUlvE_clEv + 80
12 libtensorflow_framework.2.dylib 0x000000011c00fae0 _ZN10tensorflow12_GLOBAL__N_17PThread8ThreadFnEPv + 104
13 libsystem_pthread.dylib 0x00000001903ee06c _pthread_start + 320
14 libsystem_pthread.dylib 0x00000001903e8da0 thread_start + 8

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

No branches or pull requests

5 participants