Class: Cohere::Transcribe::Safetensors::DTypeConverter
- Inherits:
-
Object
- Object
- Cohere::Transcribe::Safetensors::DTypeConverter
- Defined in:
- lib/cohere/transcribe/safetensors.rb
Overview
Portable Ruby dtype conversion. Conversion is chunked by Reader, so memory use remains bounded even when this fallback is used.
Direct Known Subclasses
Class Attribute Summary collapse
Instance Method Summary collapse
Class Attribute Details
.default ⇒ Object
287 288 289 290 291 292 |
# File 'lib/cohere/transcribe/safetensors.rb', line 287 def default return @default if @default @default = NativeDTypeConverter.auto @default || (@portable_fallback ||= new) end |
Instance Method Details
#convert(bytes, from:, to:) ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/cohere/transcribe/safetensors.rb', line 297 def convert(bytes, from:, to:) from = from.to_s.upcase to = to.to_s.upcase validate_input!(bytes, from) return bytes.dup if from == to case [from, to] when %w[BF16 F32] then bf16_to_f32(bytes) when %w[BF16 F16] then bf16_to_f16(bytes) when %w[F32 F16] then f32_to_f16(bytes) when %w[F16 F32] then f16_to_f32(bytes) when %w[F32 BF16] then f32_to_bf16(bytes) when %w[F16 BF16] then f32_to_bf16(f16_to_f32(bytes)) else raise Error, "Unsupported floating-point conversion #{from} -> #{to}" end end |