Module: Safetensors

Defined in:
lib/safetensors.rb,
lib/safetensors/numo.rb,
lib/safetensors/torch.rb,
lib/safetensors/version.rb

Defined Under Namespace

Modules: Numo, Torch Classes: Error

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.big_endian?Boolean

private

Returns:

  • (Boolean)


34
35
36
# File 'lib/safetensors.rb', line 34

def self.big_endian?
  [1].pack("i") == [1].pack("i!>")
end

.safe_open(filename, framework:, device: "cpu") ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/safetensors.rb', line 24

def self.safe_open(filename, framework:, device: "cpu")
  f = SafeOpen.new(filename, framework, device)
  if block_given?
    yield f
  else
    f
  end
end

.serialize(tensor_dict, metadata: nil) ⇒ Object



16
17
18
# File 'lib/safetensors.rb', line 16

def self.serialize(tensor_dict, metadata: nil)
  _serialize(tensor_dict, )
end

.serialize_file(tensor_dict, filename, metadata: nil) ⇒ Object



20
21
22
# File 'lib/safetensors.rb', line 20

def self.serialize_file(tensor_dict, filename, metadata: nil)
  _serialize_file(tensor_dict, filename, )
end