Comments (5)
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.
@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.
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.
@SueSu-Wish from the log, it seems the index is not saved successfully.
from sptag.
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)
- Segmentation fault (core dumped) while running quantizer
- Dockerfile doesn't work
- Logger is not configurable until after it's been used
- SPATAG build failure with cmake HOT 3
- Not enough memory on host devices offered by Azure
- thread local context (#359) causes test issue on Linux: `1: [4] fid:0 channel 2, to submit:64, submitted:Operation not permitted` HOT 18
- This repo is missing important files
- build failure with GCC 13 due to missing `#include <cstdint> in `AnnService/inc/Helper/DiskIO.h`
- index.Save function doesn't create the file on disk HOT 1
- How to Search SPANN SSD Index???
- Import SPTAG Failed
- Missing m_SPTQueue.insert()?
- [QUESTION] How to start a online server for service.ini?
- Multiple connection for one server (to be assigned for each client)
- How to use distribute server? HOT 2
- compile failed with bug
- KMeans clustering
- Improve the BalancedDataPartition program
- Building a 1000W BKT index crashes
- Unable to download vectors_9.bin and vectors_12.bin using git lfs pull
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sptag.