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

[TARGET] Cleanup the target_host usage to new target style. #9497

Merged
merged 1 commit into from
Nov 12, 2021

Conversation

tqchen
Copy link
Member

@tqchen tqchen commented Nov 11, 2021

As we move towards the new Target system, most of the target specifications in the compiler already moved to the new style. This PR aims to cleanup the rest in the codebase.

  • Add deprecation warnings to functions with target_host parameters.
  • Update the build usage to new target style.

@Mousius
Copy link
Member

Mousius commented Nov 11, 2021

Hi @tqchen,

Is there an RFC or tracking issue for this you can link to this?

@junrushao
Copy link
Member

@junrushao
Copy link
Member

CC: @zxybazh

@tqchen
Copy link
Member Author

tqchen commented Nov 11, 2021

These were the left over items that should have been done as part of the Target system refactor. Most of the tutorials already moved to the new styles in previous refactor by @zxybazh , this PR aims to cleanup the rest.

@tqchen tqchen changed the title [TARGET] Move target_host usage to new target style. [TARGET] Cleanup the target_host usage to new target style. Nov 11, 2021
- Add deprecation warnings to functions with target_host parameters.
- Update the build usage to new target style.
Copy link
Member

@zxybazh zxybazh left a comment

Choose a reason for hiding this comment

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

Generally the PR looks good to me and thanks TQ for the very detailed follow up and adding warnings for target host deprecation. It's long been my hope that we can completely get rid of target host as an addtional argument and have a concise and united target representation. I am very supportive of the change and it takes a lot of effort to change all occurences of target host.

It's very easy to overlook some function calls to give warnings so here I propose to update the check_and_update_host_consist function as follows to check if we are dispatching a new target host for any target with no current target host.

    @staticmethod
    def check_and_update_host_consist(target, host=None, target_is_dict_key=True):
        """A helper function that merges a legacy "target, target_host" pair, then returns
        the merged target and its host field. The function is for legacy target and target
        host pair only, and should not be used in the new target system.

        Parameters
        ----------
        target : Union[str, Dict[str, Any], Target]
            The target or heterogeneous target
        host : Union[str, Dict[str, Any], Target, None]
            The target host
        target_is_dict_key : Bool
            When the type of target is dict, whether Target is the key (Otherwise the value)
        """
        if target is None:
            assert host is None, "Target host is not empty when target is empty."
            return target, host
        warning_flag = False
        if isinstance(target, dict) and "kind" not in target:
            new_target = {}
            for tgt, mod in target.items():
                if not target_is_dict_key:
                    tgt, mod = mod, tgt
                if isinstance(tgt, (dict, str, Target)):
                    tgt, host = Target.check_and_update_host_consist(tgt, host)
                if not target_is_dict_key:
                    tgt, mod = mod, tgt
                new_target[tgt] = mod
            target = new_target

        else:
            warning_flag = (host is not None) and (target.host is None)
            target = Target(target, host)
            host = target.host
        if warning_flag:
            warnings.warn(
                "target_host parameter is going to be deprecated. "
                "Please pass in tvm.target.Target(target, host=target_host) instead."
            )
        return target, host

warnings.warn(
"target_host parameter is going to be deprecated. "
"Please pass in tvm.target.Target(target, host=target_host) instead."
)
Copy link
Member

@zxybazh zxybazh Nov 12, 2021

Choose a reason for hiding this comment

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

Shall we also add the warning to extract_from_multiple_program as well?

Comment on lines 352 to 355
if isinstance(target_host, (str, Target)):
target_host = Target(target_host)
elif target_host:
raise ValueError("target host must be the type of str, " + "tvm.target.Target, or None")
Copy link
Member

@zxybazh zxybazh Nov 12, 2021

Choose a reason for hiding this comment

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

This part seems to be obsolete after the change, would be great to remove.

Copy link
Member Author

Choose a reason for hiding this comment

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

since we only issue an warning, we might still want to keep this one

Copy link
Member

@zxybazh zxybazh Nov 12, 2021

Choose a reason for hiding this comment

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

The type is already checked when doing check_and_update_host_consist when it calls target = Target(target, host), see here. I'll remove it and check if there are other obsolete parts in my follow up PR.

@Hzfengsy Hzfengsy merged commit 137def8 into apache:main Nov 12, 2021
@tqchen
Copy link
Member Author

tqchen commented Nov 12, 2021

Thanks @zxybazh , given check_and_update_host_consist can be called multiple times, it may not be desirable to do so(for the second time it is called). So I think we can still take the explicit approach. The suggestion of extract_from_multiple_program is great, can you send a followup PR?

@zxybazh
Copy link
Member

zxybazh commented Nov 12, 2021

Sounds good. I'll send a follow up PR.

mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
- Add deprecation warnings to functions with target_host parameters.
- Update the build usage to new target style.
mehrdadh pushed a commit to mehrdadh/tvm that referenced this pull request Dec 1, 2021
- Add deprecation warnings to functions with target_host parameters.
- Update the build usage to new target style.
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 7, 2022
- Add deprecation warnings to functions with target_host parameters.
- Update the build usage to new target style.
yangulei pushed a commit to yangulei/tvm that referenced this pull request Jan 11, 2022
- Add deprecation warnings to functions with target_host parameters.
- Update the build usage to new target style.
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
- Add deprecation warnings to functions with target_host parameters.
- Update the build usage to new target style.
@tqchen tqchen deleted the target branch February 26, 2023 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants