Giter Site home page Giter Site logo

Segmentation fault (core dumped) about sptag HOT 5 OPEN

microsoft avatar microsoft commented on August 23, 2024
Segmentation fault (core dumped)

from sptag.

Comments (5)

MaggieQi avatar MaggieQi commented on August 23, 2024 1

Currently, we only support np.float32 type. np.random.uniform will generate np.float64 data. Try to use np.random.uniform(low=0.5, high=13.3, size=(n,)).astype(np.float32)

from sptag.

SueSu-Wish avatar SueSu-Wish commented on August 23, 2024

@MaggieQi I also got segmentation fault with np.float32 type.
python 2.7, ubuntu 14.04

import SPTAG
import numpy as np

n = 100
k = 3
r = 3

def testBuild(algo, distmethod, x, out):
   i = SPTAG.AnnIndex(algo, 'Float', x.shape[1])
   i.SetBuildParam("NumberOfThreads", '4')
   i.SetBuildParam("DistCalcMethod", distmethod)
   ret = i.Build(x.tobytes(), x.shape[0])
   i.Save(out)

def testBuildWithMetaData(algo, distmethod, x, s, out):
   i = SPTAG.AnnIndex(algo, 'Float', x.shape[1])
   i.SetBuildParam("NumberOfThreads", '4')
   i.SetBuildParam("DistCalcMethod", distmethod)
   if i.BuildWithMetaData(x.tobytes(), s, x.shape[0]):
       i.Save(out)

def testSearch(index, q, k):
   j = SPTAG.AnnIndex.Load(index)
   for t in range(q.shape[0]):
       result = j.Search(q[t].tobytes(), k)
       print (result[0]) # ids
       print (result[1]) # distances

def testSearchWithMetaData(index, q, k):
   j = SPTAG.AnnIndex.Load(index)
   j.SetSearchParam("MaxCheck", '1024')
   for t in range(q.shape[0]):
       result = j.SearchWithMetaData(q[t].tobytes(), k)
       print (result[0]) # ids
       print (result[1]) # distances
       print (result[2]) # metadata

def testAdd(index, x, out, algo, distmethod):
   if index != None:
       i = SPTAG.AnnIndex.Load(index)
   else:
       i = SPTAG.AnnIndex(algo, 'Float', x.shape[1])
   i.SetBuildParam("NumberOfThreads", '4')
   i.SetBuildParam("DistCalcMethod", distmethod)
   if i.Add(x.tobytes(), x.shape[0]):
       i.Save(out)

def testAddWithMetaData(index, x, s, out, algo, distmethod):
   if index != None:
       i = SPTAG.AnnIndex.Load(index)
   else:
       i = SPTAG.AnnIndex(algo, 'Float', x.shape[1])
   i = SPTAG.AnnIndex(algo, 'Float', x.shape[1])
   i.SetBuildParam("NumberOfThreads", '4')
   i.SetBuildParam("DistCalcMethod", distmethod)
   if i.AddWithMetaData(x.tobytes(), s, x.shape[0]):
       i.Save(out)

def testDelete(index, x, out):
   i = SPTAG.AnnIndex.Load(index)
   ret = i.Delete(x.tobytes(), x.shape[0])
   print (ret)
   i.Save(out)

def Test(algo, distmethod):
   x = np.ones((n, 10), dtype=np.float32) * np.reshape(np.arange(n, dtype=np.float32), (n, 1))
   q = np.ones((r, 10), dtype=np.float32) * np.reshape(np.arange(r, dtype=np.float32), (r, 1)) * 2
   print x
   print q
   m = ''
   for i in range(n):
       m += str(i) + '\n'

   print ("Build.............................")
   testBuild(algo, distmethod, x, 'testindices')
   testSearch('testindices', q, k)
   print ("Add.............................")
   testAdd('testindices', x, 'testindices', algo, distmethod)
   testSearch('testindices', q, k)
   print ("Delete.............................")
   testDelete('testindices', q, 'testindices')
   testSearch('testindices', q, k)

   print ("AddWithMetaData.............................")
   testAddWithMetaData(None, x, m, 'testindices', algo, distmethod)
   print ("Delete.............................")
   testSearchWithMetaData('testindices', q, k)
   testDelete('testindices', q, 'testindices')
   testSearchWithMetaData('testindices', q, k)

if __name__ == '__main__':
   Test('BKT', 'L2')
   Test('KDT', 'L2')

Build.............................
Setting NumberOfThreads with value 4
Setting DistCalcMethod with value L2
Start to build BKTree 1
1 BKTree built, 101 100
build RNG graph!
Refine 1 0%Refine RNG, graph acc:1
Refine 2 0%Refine RNG, graph acc:1
Build RNG Graph end!
[-1, -1, -1]
[3.4028234663852886e+38, 3.4028234663852886e+38, 3.4028234663852886e+38]
[-1, -1, -1]
[3.4028234663852886e+38, 3.4028234663852886e+38, 3.4028234663852886e+38]
[-1, -1, -1]
[3.4028234663852886e+38, 3.4028234663852886e+38, 3.4028234663852886e+38]
Add.............................
Setting NumberOfThreads with value 4
Setting DistCalcMethod with value L2
[-1, -1, -1]
[3.4028234663852886e+38, 3.4028234663852886e+38, 3.4028234663852886e+38]
[-1, -1, -1]
[3.4028234663852886e+38, 3.4028234663852886e+38, 3.4028234663852886e+38]
[-1, -1, -1]
[3.4028234663852886e+38, 3.4028234663852886e+38, 3.4028234663852886e+38]
Delete.............................
False
Segmentation fault (core dumped)

from sptag.

0xhanh avatar 0xhanh commented on August 23, 2024

Currently, we only support np.float32 type. np.random.uniform will generate np.float64 data. Try to use np.random.uniform(low=0.5, high=13.3, size=(n,)).astype(np.float32)

Passed, thanks

from sptag.

MaggieQi avatar MaggieQi commented on August 23, 2024

@SueSu-Wish from the log, it seems the index is not saved successfully.

from sptag.

sruti25 avatar sruti25 commented on August 23, 2024

Trying to run IndexBuilder from command line like this:
./indexbuilder -d 1 -v Float -i ../all_question_embeddings.txt -o index/ -a BKT -t 4
but end up getting segmentation fault. I am using np.float32 as the data type.

Setting NumberOfThreads with value 4
Begin Subtask: 0, start offset position:0
Begin Subtask: 1, start offset position:2420000
Begin Subtask: 2, start offset position:4840000
Begin Subtask: 3, start offset position:7260000
Start to build BKTree 1
1 BKTree built, 4001 4000
build RNG graph!
Parallel TpTree Partition begin
Segmentation fault

from sptag.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.