Skip to content

feat(transformers): add Nougat example#1336

Merged
vigo999 merged 2 commits intomindspore-lab:masterfrom
hadipash:nougat
Sep 30, 2025
Merged

feat(transformers): add Nougat example#1336
vigo999 merged 2 commits intomindspore-lab:masterfrom
hadipash:nougat

Conversation

@hadipash
Copy link
Copy Markdown
Collaborator

Relies of PR #1271

Add:

  • Nougat model example.

Usage:

from datasets import load_dataset
from transformers import NougatProcessor

from mindspore import tensor

from mindone.transformers import VisionEncoderDecoderModel

processor = NougatProcessor.from_pretrained("facebook/nougat-base")
model = VisionEncoderDecoderModel.from_pretrained("facebook/nougat-base")

# prepare PDF image for the model
dataset = load_dataset("hf-internal-testing/fixtures_docvqa")
image = dataset["test"][0]["image"].convert("RGB")
pixel_values = tensor(processor(image, return_tensors="np").pixel_values)

# generate transcription (here we only generate 30 tokens)
outputs = model.generate(
    pixel_values, min_length=1, max_new_tokens=30, bad_words_ids=[[processor.tokenizer.unk_token_id]]
)

sequence = processor.batch_decode(outputs, skip_special_tokens=True)[0]
sequence = processor.post_process_generation(sequence, fix_markdown=False)
print(sequence)

Performance:

The experiments were performed on Ascend Atlas 800T A2 hardware, utilizing MindSpore 2.6.0 in PyNative mode.

Model Precision Weight loading (s) Speed
VisionEncoderDecoderModel FP32 18 22 token/s

@hadipash hadipash requested a review from vigo999 as a code owner September 29, 2025 09:35
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @hadipash, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates a practical example for the Nougat model, a Vision Transformer designed for Optical Character Recognition (OCR) of academic documents, into the mindone.transformers framework. The example provides a clear demonstration of how to use the model to convert PDF images into markdown text, enhancing accessibility to scientific knowledge. It serves as a valuable resource for developers looking to leverage Nougat's capabilities for document processing tasks.

Highlights

  • New Nougat Model Example: This pull request introduces a new example for the Nougat model, demonstrating its usage for Optical Character Recognition (OCR) on scientific documents within the mindone.transformers library.
  • Comprehensive Documentation: A README.md file has been added for the Nougat example, providing an overview of the model, its architecture, and detailed instructions on how to perform inference using NougatProcessor and VisionEncoderDecoderModel.
  • Practical Usage Snippet: The example includes a Python code snippet that showcases how to load a dataset, preprocess an image, generate transcription, and post-process the output, making it easy for users to get started.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a well-documented example for the Nougat model, including a README.md with an overview and usage instructions. The example is clear and helpful. My only suggestion is to include the performance metrics from the pull request description in the README.md to provide users with a more complete picture of the model's capabilities.

11:39 a.m.
Coffee Break
11:39 a.
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This is a great example for the Nougat model. To make it even more complete, consider adding the performance metrics you've included in the pull request description to this README. This provides users with valuable information about the model's performance on specific hardware.

You can add the following section at the end of the file:

## Performance

The experiments were performed on Ascend Atlas 800T A2 hardware, utilizing MindSpore 2.6.0 in PyNative mode.

| Model                     | Precision | Weight loading (s) |   Speed    |
|---------------------------|:---------:|:------------------:|:----------:|
| VisionEncoderDecoderModel |   FP32    |         18         | 22 token/s |

@vigo999 vigo999 added the new model add new model to mindone label Sep 29, 2025
@vigo999 vigo999 added this to mindone Sep 29, 2025
@vigo999 vigo999 moved this to In Progress in mindone Sep 29, 2025
@SamitHuang
Copy link
Copy Markdown
Collaborator

pls resolve linting errors

@vigo999 vigo999 added this pull request to the merge queue Sep 30, 2025
Merged via the queue into mindspore-lab:master with commit ff5372d Sep 30, 2025
3 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in mindone Sep 30, 2025
@hadipash hadipash deleted the nougat branch September 30, 2025 09:55
zackcxb pushed a commit to zackcxb/mindone that referenced this pull request Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new model add new model to mindone

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants