-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
8d5feb8
to
4c883f3
Compare
Hi @tqchen, Is there an RFC or tracking issue for this you can link to this? |
CC: @zxybazh |
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. |
- Add deprecation warnings to functions with target_host parameters. - Update the build usage to new target style.
There was a problem hiding this 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." | ||
) |
There was a problem hiding this comment.
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?
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Thanks @zxybazh , given |
Sounds good. I'll send a follow up PR. |
- Add deprecation warnings to functions with target_host parameters. - Update the build usage to new target style.
- Add deprecation warnings to functions with target_host parameters. - Update the build usage to new target style.
- Add deprecation warnings to functions with target_host parameters. - Update the build usage to new target style.
- Add deprecation warnings to functions with target_host parameters. - Update the build usage to new target style.
- Add deprecation warnings to functions with target_host parameters. - Update the build usage to new target style.
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.