[RFC]: DLPack based exchange of dtype and Device

Aperta
#972 3 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
api

Direzione di ricerca

Non sono specificati file di implementazione né test. Inizia esaminando le interfacce dtype e Device esistenti di array API insieme alle definizioni di DLDataType e DLDevice di DLPack, quindi determina se i metodi proposti e il supporto per from_dlpack rientrano nell’ambito. Il lavoro è completato quando l’ambito e la specifica dell’interfaccia sono stati concordati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

API extension Needs Discussion RFC topic: Device Handling topic: DLPack

Background

As of now we have standard interface for exchanging tensors through DLPack. One minor but still useful thing is to also provide a mechanism for solutions. Motivating example

import numpy
import torch

# results in error
torch.empty((1, 2), dtype=numpy.float16)
# results in error
numpy.empty((1, 2), dtype=torch.float16)

It could be useful for the package.dtype and package.Device to be able to provide an interface for exchange such information. Given we already have DLDataType and DLDevice in dlpack, it might be helpful to bringup interfaces to transparently expose them. Such information can also be helpful for bindings to implement generic support for these types

Proposal

# defined in dtype
class dtype:
    def __dlpack_data_type__():
         """Return a tuple (code, bits, lanes) in DLDataType format 
         """

# defined in Device
class Device:
    def __dlpack_device__():
         """Return a tuple of (device_type, device_id) """

Then if desirable, the interface could implement something like

def empty(shape, dtype):
     if hasattr(dtype, "___dlpack_data_type__"):
           convert

There is also possibility of trying to run general value conversion. I do not think we have to update from_dlpack to also support these values, but there is an option to do so

def from_dlpack(src):
      if hasattr(src, "__dlpack__"):
            # this is an array
      if hasattr(src, "__dlpack_data_type__"):
            # this is a dtype
      if hasattr(src, "__dlpack_device__"):
            # this is a device
Lingua principale
Python
Stelle
281
Fork
52
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di data-apis/array-api

Tutte le issue di data-apis/array-api

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.