17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/informers/models.rb', line 17
def self.from_pretrained(
pretrained_model_name_or_path,
quantized: true,
progress_callback: nil,
config: nil,
cache_dir: nil,
local_files_only: false,
revision: "main",
device: nil,
dtype: nil,
model_file_name: nil,
session_options: {}
)
options = {
quantized:,
progress_callback:,
config:,
cache_dir:,
local_files_only:,
revision:,
device:,
dtype:,
model_file_name:,
session_options:
}
config = AutoConfig.from_pretrained(pretrained_model_name_or_path, **options)
if options[:config].nil?
options[:config] = config
end
if !const_defined?(:MODEL_CLASS_MAPPINGS)
raise Error, "`MODEL_CLASS_MAPPINGS` not implemented for this type of `AutoClass`: #{name}"
end
const_get(:MODEL_CLASS_MAPPINGS).each do |model_class_mapping|
model_info = model_class_mapping[config[:model_type]]
if !model_info
next end
return model_info[1].from_pretrained(pretrained_model_name_or_path, **options)
end
if const_defined?(:BASE_IF_FAIL)
warn "Unknown model class #{config[:model_type].inspect}, attempting to construct from base class."
PreTrainedModel.from_pretrained(pretrained_model_name_or_path, **options)
else
raise Error, "Unsupported model type: #{config[:model_type]}"
end
end
|