Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Bug]: Using GPU_IVF_FLAT and COSINE wtih the same parameters as IVF_FLAT brings errors #36605

Closed
1 task done
qwevdb opened this issue Sep 29, 2024 · 3 comments
Closed
1 task done
Assignees
Labels
kind/bug Issues or changes related a bug needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. stale indicates no udpates for 30 days

Comments

@qwevdb
Copy link

qwevdb commented Sep 29, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Environment

- Milvus version: milvus v2.4.12-gpu
- Deployment mode(standalone or cluster): standalone
- MQ type(rocksmq, pulsar or kafka): rocksmq   
- SDK version(e.g. pymilvus v2.0.0rc2): pymilvus v2.4.5
- OS(Ubuntu or CentOS): Ubuntu 24.04 LTS
- CPU/Memory: Intel Core i7-11700 / 64G
- GPU: NVIDIA GeForce RTX 4090
- Others:

Current Behavior

Using the IVF_FLAT index and COSINE metric can normally output results, while using the GPU_IVF_FLAT index and COSINE metric with the same parameters produce errors.

Expected Behavior

Both IVF_FLAT and GPU_IVF_FLAT index with COSINE metric and the same parameters can produce the same results.

Steps To Reproduce

  1. run python script as follow
import time
from pymilvus import Collection, connections, FieldSchema, CollectionSchema, DataType, utility
import numpy as np

FLOAT_MAX = 5000
DATA_INT_MAX = 100

numpy_random = np.random.default_rng(0)
alias = "bench"
collection_name = "Benchmark"
client = connections.connect(
   alias=alias,
   host="localhost",
   port="19530"
)
if utility.has_collection(collection_name, using=alias):
   collection = Collection(name=collection_name, using=alias)
   collection.drop()
   time.sleep(2)  
   
dim = 275
id = FieldSchema(name='id', dtype=DataType.INT64, is_primary=True)
vector = FieldSchema(name='vector', dtype=DataType.FLOAT_VECTOR, dim=dim)
fields = [id, vector]
schema = CollectionSchema(fields=fields, description=alias)
collection = Collection(
   name=collection_name,
   schema=schema,
   using=alias,
)
index_params = {'index_type': 'IVF_FLAT', 'params': {'nlist': 57953}, 'metric_type': 'COSINE'}
# index_params = {'index_type': 'GPU_IVF_FLAT', 'params': {'nlist': 57953}, 'metric_type': 'COSINE'}
collection.create_index("vector", index_params, timeout=100)

dataset = []
number = 2297
for i in range(0, number + 0):
   vector = numpy_random.random((1, dim))
   data = {
       'id': i,
       'vector': list(vector[0]),

   }
   dataset.append(data)
collection.upsert(dataset)
collection.flush()
collection.load()

dataset = []
number = 64
for i in range(2297,number + 2297):
   vector = numpy_random.random((1, dim))
   data = {
       'id': i,
       'vector': list(vector[0]),

   }
   dataset.append(data)
collection.insert(dataset)
collection.flush()
collection.load()

vector = numpy_random.random((1, dim))
query_vector = list(vector[0])
iterator = collection.search_iterator(
      data=[query_vector],
      anns_field="vector",
      param={"metric_type": "COSINE", "params": {'nprobe': 13289}},
      limit=8,
      expr=None,
      batch_size=6609,
      timeout=100
   )
res1 = []
while True:
   result = iterator.next()
   if not result:
       iterator.close()
       break

   res1.extend(result)
collection.release()
collection.drop_index()
collection.flush()
print(res1)
collection.drop()

result:

[id: 1303, distance: 0.7831529378890991, entity: {}, id: 2142, distance: 0.782934844493866, entity: {}, id: 893, distance: 0.7822405099868774, entity: {}, id: 1443, distance: 0.7811518907546997, entity: {}, id: 1333, distance: 0.7790765762329102, entity: {}, id: 2308, distance: 0.7782455682754517, entity: {}, id: 32, distance: 0.7777007818222046, entity: {}, id: 490, distance: 0.777592658996582, entity: {}]
  1. change 'index_type': 'IVF_FLAT' to 'index_type': 'GPU_IVF_FLAT' in index_params and run again

result:

RPC error: [create_index], <MilvusException: (code=1100, message=metric type not found or not supported, supported: [L2 IP]: invalid parameter[expected=valid index params][actual=invalid index params])>, <Time:{'RPC start': '2024-09-29 22:15:23.000733', 'RPC error': '2024-09-29 22:15:23.002850'}>
Traceback (most recent call last):
  File "/home/xxx/Desktop/vdb/milvus/vdb-test/./log/milvus/test_bug1_B.py", line 32, in <module>
    collection.create_index("vector", index_params1, timeout=100)
  File "/root/anaconda3/envs/milvus/lib/python3.10/site-packages/pymilvus/orm/collection.py", line 1373, in create_index
    return conn.create_index(self._name, field_name, index_params, timeout=timeout, **kwargs)
  File "/root/anaconda3/envs/milvus/lib/python3.10/site-packages/pymilvus/decorators.py", line 148, in handler
    raise e from e
  File "/root/anaconda3/envs/milvus/lib/python3.10/site-packages/pymilvus/decorators.py", line 144, in handler
    return func(*args, **kwargs)
  File "/root/anaconda3/envs/milvus/lib/python3.10/site-packages/pymilvus/decorators.py", line 183, in handler
    return func(self, *args, **kwargs)
  File "/root/anaconda3/envs/milvus/lib/python3.10/site-packages/pymilvus/decorators.py", line 123, in handler
    raise e from e
  File "/root/anaconda3/envs/milvus/lib/python3.10/site-packages/pymilvus/decorators.py", line 87, in handler
    return func(*args, **kwargs)
  File "/root/anaconda3/envs/milvus/lib/python3.10/site-packages/pymilvus/client/grpc_handler.py", line 987, in create_index
    check_status(status)
  File "/root/anaconda3/envs/milvus/lib/python3.10/site-packages/pymilvus/client/utils.py", line 63, in check_status
    raise MilvusException(status.code, status.reason, status.error_code)
pymilvus.exceptions.MilvusException: <MilvusException: (code=1100, message=metric type not found or not supported, supported: [L2 IP]: invalid parameter[expected=valid index params][actual=invalid index params])>
@qwevdb qwevdb added kind/bug Issues or changes related a bug needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Sep 29, 2024
@xiaofan-luan
Copy link
Collaborator

GPU index only support L2 IP, cosine is not supported yet.
However, you can normalize vector so IP distance is same as L2

@yanliang567
Copy link
Contributor

/assign @qwevdb
/unassign

@sre-ci-robot sre-ci-robot assigned qwevdb and unassigned yanliang567 Sep 30, 2024
Copy link

stale bot commented Nov 9, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Rotten issues close after 30d of inactivity. Reopen the issue with /reopen.

@stale stale bot added the stale indicates no udpates for 30 days label Nov 9, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
kind/bug Issues or changes related a bug needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. stale indicates no udpates for 30 days
Projects
None yet
Development

No branches or pull requests

3 participants