Does the amax and max functions from the cupy library in python hold an error, when using matrices, with only one column or only one row?

153 views Asked by At

I tried implementing the softmax activation function for machine learning and image classification using Cupy for GPU acceleration. I observed that for arrays with shapes NX1 or 1XN, Cupys max function outputs an error. However, for all other cases with NXA, where N and A are both whole numbers other than 1, it works perfectly fine.

My Code:

def softmax_(Z):
    max_Z = cp.max(Z, axis=0, keepdims=True)  # problematic max function
    exp_Z = cp.exp(Z - max_Z)  # Subtracting the maximum value for numerical stability
    sum_exp_Z = cp.sum(exp_Z, axis=0, keepdims=True)  # Summing up the values
    return exp_Z / sum_exp_Z  # dividing them to get the softmax

array1 = cp.random.randn(3, 4)  # 3x4
array2 = cp.random.randn(5, 1)  # 5x1

print(softmax_(array1))  # no error
print(softmax_(array2))  # produces an error

My OSError, which I am inexperienced with:

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: 'C:\\Users\\confidential\\.cupy\\jitify_cache\\tmp1pxgjv_g' -> 'C:\\Users\\confidential/.cupy/jitify_cache/jitify_<unknown>_200200_12030_2_b3452ffa79e273adadd0403b6b0c05b78158b1e0.json'

The output for array 1

Output: [[0.17813469 0.20912114 0.19734889 0.30515635] [0.42569072 0.47354802 0.4463671 0.20997539] [0.39617459 0.31733085 0.356284 0.48486825]]

The error for array2:

../../util_ptx.cuh(38): warning: util_type.cuh: [jitify] File not found 
../../util_ptx.cuh(41): warning: util_debug.cuh: [jitify] File not found
../../thread/thread_load.cuh(40): warning: ../util_ptx.cuh: [jitify] File not found
Traceback (most recent call last):
  File "c:\Users\confidential\Desktop\Projekte\Neural_network2\test.py", line 14, in <module>        
    print(softmax_(array2))
          ^^^^^^^^^^^^^^^^
  File "c:\Users\confidential\Desktop\Projekte\Neural_network2\test.py", line 4, in softmax_
    `max_Z = cp.max(Z, axis=0, keepdims=True)`
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\confidential\PycharmProjects\nunpy\venv\Lib\site-packages\cupy\_statistics\order.py", line 81, in amax
    return a.max(axis=axis, out=out, keepdims=keepdims)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "cupy\_core\core.pyx", line 990, in cupy._core.core._ndarray_base.max
  File "cupy\_core\core.pyx", line 998, in cupy._core.core._ndarray_base.max
  File "cupy\_core\_routines_statistics.pyx", line 43, in cupy._core._routines_statistics._ndarray_max
  File "cupy\_core\_reduction.pyx", line 618, in cupy._core._reduction._SimpleReductionKernel.__call__
  File "cupy\_core\_reduction.pyx", line 370, in cupy._core._reduction._AbstractReductionKernel._call
  File "cupy\_core\_cub_reduction.pyx", line 689, in cupy._core._cub_reduction._try_to_call_cub_reduction
  File "cupy\_core\_cub_reduction.pyx", line 540, in cupy._core._cub_reduction._launch_cub    
  File "cupy\_util.pyx", line 64, in cupy._util.memoize.decorator.ret
  File "cupy\_core\_cub_reduction.pyx", line 240, in cupy._core._cub_reduction._SimpleCubReductionKernel_get_cached_function
  File "cupy\_core\_cub_reduction.pyx", line 223, in cupy._core._cub_reduction._create_cub_reduction_function
  File "cupy\_core\core.pyx", line 2254, in cupy._core.core.compile_with_cache
  File "C:\Users\confidential\PycharmProjects\nunpy\venv\Lib\site-packages\cupy\cuda\compiler.py", line 484, in _compile_module_with_cache
    return _compile_with_cache_cuda(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\confidential\PycharmProjects\nunpy\venv\Lib\site-packages\cupy\cuda\compiler.py", line 562, in _compile_with_cache_cuda
    ptx, mapping = compile_using_nvrtc(
                   ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\confidential\PycharmProjects\nunpy\venv\Lib\site-packages\cupy\cuda\compiler.py", line 319, in compile_using_nvrtc
    return _compile(source, options, cu_path,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\confidential\PycharmProjects\nunpy\venv\Lib\site-packages\cupy\cuda\compiler.py", line 284, in _compile
    options, headers, include_names = _jitify_prep(
                                      ^^^^^^^^^^^^^
  File "C:\Users\confidential\PycharmProjects\nunpy\venv\Lib\site-packages\cupy\cuda\compiler.py", line 233, in _jitify_prep
    jitify._init_module()
  File "cupy\cuda\jitify.pyx", line 212, in cupy.cuda.jitify._init_module
  File "cupy\cuda\jitify.pyx", line 233, in cupy.cuda.jitify._init_module
  File "cupy\cuda\jitify.pyx", line 209, in cupy.cuda.jitify._init_cupy_headers
  File "cupy\cuda\jitify.pyx", line 198, in cupy.cuda.jitify._init_cupy_headers_from_scratch  
  File "cupy\cuda\jitify.pyx", line 128, in cupy.cuda.jitify.dump_cache
OSError: [WinError 123] The syntax for the file name, directory name, or volume label is incorrect: 'C:\\Users\\confidential\\.cupy\\jitify_cache\\tmps16uxq46' -> 'C:\\Users\\confidential/.cupy/jitify_cache/jitify_<unknown>_200200_12030_2_b3452ffa79e273adadd0403b6b0c05b78158b1e0.json'
1

There are 1 answers

0
Leo Fang On

File "cupy\cuda\jitify.pyx", line 212, in cupy.cuda.jitify._init_module File "cupy\cuda\jitify.pyx", line 233, in cupy.cuda.jitify._init_module File "cupy\cuda\jitify.pyx", line 209, in cupy.cuda.jitify._init_cupy_headers File "cupy\cuda\jitify.pyx", line 198, in cupy.cuda.jitify.init_cupy_headers_from_scratch
File "cupy\cuda\jitify.pyx", line 128, in cupy.cuda.jitify.dump_cache OSError: [WinError 123] The syntax for the file name, directory name, or volume label is incorrect: 'C:\Users\confidential\.cupy\jitify_cache\tmps16uxq46' -> 'C:\Users\confidential/.cupy/jitify_cache/jitify
_200200_12030_2_b3452ffa79e273adadd0403b6b0c05b78158b1e0.json'

This is a known issue for CuPy v13.0.0 on Windows. I fixed it upstream and it'd be included in v13.1.0.