Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/tasks/src/model-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export interface ModelData {
quant_method?: string;
};
tokenizer_config?: TokenizerConfig;
processor_config?: {
chat_template?: string;
};
chat_template_jinja?: string;
adapter_transformers?: {
model_name?: string;
model_class?: string;
Expand Down
7 changes: 6 additions & 1 deletion packages/tasks/src/model-libraries-snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,11 @@ export const terratorch = (model: ModelData): string[] => [
model = BACKBONE_REGISTRY.build("${model.id}")`,
];

const hasChatTemplate = (model: ModelData): boolean =>
model.config?.tokenizer_config?.chat_template !== undefined ||
model.config?.processor_config?.chat_template !== undefined ||
model.config?.chat_template_jinja !== undefined;

export const transformers = (model: ModelData): string[] => {
const info = model.transformersInfo;
if (!info) {
Expand All @@ -1498,7 +1503,7 @@ export const transformers = (model: ModelData): string[] => {
`${processorVarName} = ${info.processor}.from_pretrained("${model.id}"` + remote_code_snippet + ")",
`model = ${info.auto_model}.from_pretrained("${model.id}"` + remote_code_snippet + ")"
);
if (model.tags.includes("conversational")) {
if (model.tags.includes("conversational") && hasChatTemplate(model)) {
if (model.tags.includes("image-text-to-text")) {
autoSnippet.push(
"messages = [",
Expand Down
Loading