Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template.py AutoTemplate.load_from method read file with encoding utf8 #7558

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

anexplore
Copy link
Contributor

PR types

Bug fixes

PR changes

Others

Description

because Template.save write to file with encoding utf-8, however AutoTemplate.load_from() read file with platform default encoding, So when the default encoding is GBK,AutoTemplate.load_from() will read a utf8 encoded file with gbk, this will throw error.

Template.save()

    def save(self, save_path):
        if not os.path.exists(save_path):
            os.makedirs(save_path, exist_ok=True)
        template_config_file = os.path.join(save_path, TEMPLATE_CONFIG_FILE)
        template_class = self.__class__.__name__
        with open(template_config_file, "w", encoding="utf-8") as fp:
            fp.write(json.dumps(self._prompt, ensure_ascii=False) + "\n")
            fp.write(json.dumps({"class": template_class}, ensure_ascii=False) + "\n")
        template_param_file = os.path.join(save_path, TEMPLATE_PARAMETER_FILE)

AutoTemplate.load_from()

    def load_from(
        cls, data_path: os.PathLike, tokenizer: PretrainedTokenizer, max_length: int, model: PretrainedModel = None
    ):
        template_config_file = os.path.join(data_path, TEMPLATE_CONFIG_FILE)
        if not os.path.isfile(template_config_file):
            raise ValueError("{} not found under {}".format(TEMPLATE_CONFIG_FILE, data_path))
        with open(template_config_file, "r") as fp:
            config = [x.strip() for x in fp]
            prompt = json.loads(config[0])
            if len(config) > 1:
                template_class = json.loads(config[1])["class"]

@CLAassistant
Copy link

CLAassistant commented Nov 30, 2023

CLA assistant check
All committers have signed the CLA.

Copy link

codecov bot commented Nov 30, 2023

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (5500d09) 57.91% compared to head (5f6b9be) 57.91%.
Report is 1 commits behind head on develop.

Files Patch % Lines
...erimental/transformers/fused_transformer_layers.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7558      +/-   ##
===========================================
- Coverage    57.91%   57.91%   -0.01%     
===========================================
  Files          579      579              
  Lines        86390    86392       +2     
===========================================
  Hits         50036    50036              
- Misses       36354    36356       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@sijunhe sijunhe left a comment

Choose a reason for hiding this comment

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

lgtm. thank you for the contribution!

@sijunhe sijunhe merged commit 74bb39b into PaddlePaddle:develop Dec 4, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants